Java Configuration MyEclipse MAVEN environment specific implementation steps _java

Source: Internet
Author: User

Java Configuration myeclipse maven environment

Although most of my projects have moved to idea, it is customary to open myeclipse when writing part of a small test program. I used to download jar packages before using Third-party libraries, and then build path to import them, but it seems more convenient to configure MAVEN dependencies in idea. So I also want to use Pom.xml to import dependencies in MyEclipse, I encountered some problems in the process of trying, I am here to record the way to solve these problems.

Environment

MyEclipse for Spring 2014
JRE 8
Maven 3.3.3 (although MyEclipse has a mvn plugin, but I've installed mvn I don't know what the middle process is)

For the MVN function and pom.xml format does not do too much introduction, the following directly into the Ask&&answer link

1 Error: Pom.xml format is not correct

<?xml version= "1.0" encoding= "UTF-8"?> <project "xmlns=" 
     xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http ://maven.apache.org/xsd/maven-4.0.0.xsd "> 
  <modelVersion>4.0.0</modelVersion> 
 
  < groupid>test</groupid> 
  <artifactId>test-project</artifactId> 
  <version>1.0- snapshot</version> 
 
  <dependencies> 
    <dependency> 
      <groupid>joda-time</ groupid> 
      <artifactId>joda-time</artifactId> 
      <version>2.9</version> 
    </dependency> 
  </dependencies> 
</project> 

This is one of the simplest pom.xml that contains all the necessary elements,

-xml Head
-project Property Information
-modelversion
-GroupID of the product, Artifactid and version

You need to include at least three elements when configuring a dependency (the jar package you depend on)

-groupid
-artifactid
-version

And put the elements in the dependency tag and be included in the dependencies tag.

2 I don't know how to fill in the dependencies of the package I depend on

There are Web sites that search for MAVEN configuration information online

I use this a lot now.

http://mvnrepository.com/

Need to use what directly to search on the line, multiple keyword search success rate is relatively high, such as Com.google.gson Com.google and Gson two search, and finally you will get the results you want

3 fill in the dependencies but still the error to say can not download how to do

For example, depending on the JSON Lib package, we know by search that we need to fill in the following information, but we can't use it if we put it directly into Pom.xml.

<dependency> 
<span style= "White-space:pre" >  </span><groupId>net.sf.json-lib< /groupid> 
  <artifactId>json-lib</artifactId> 
  <version>2.4</version> 
< /dependency> 

There are other ways to know that there are other dependencies on this jar package that can only be used in jdk5 situations, so if the current JDK version is different, then you can't download it, so we need to configure the following form

<dependency> 
  <groupId>net.sf.json-lib</groupId> 
  <artifactid>json-lib</ artifactid> 
  <version>2.4</version> 
  <classifier>jdk15</classifier> 
</ Dependency> 

This information can only be solved by looking up the Maven dependencies of the specified package online, without a common solution.

4 I have configured the Pom.xml, then how do we import these jar dependencies

There is a difference between a common project and a MAVEN project in MyEclipse, and if you want to use MAVEN to manage dependencies and build artifacts, you need to build a MAVEN project, but the operation works very differently from what we do in idea, It also has a lot to do with our understanding (I need maven to just download the dependent Jar pack for me and I don't need him in any other case).

Here's an alternative solution, if we had a normal project, now we need to use the dependencies of the MVN Management Section, where we can convert the original project into a MAVEN project and then use the debug as-> Maven install to install the library file. After the conversion, we can still compile the export file in the way we did before, and the difference is that we can add dependencies through Pom.xml.

The way to convert it is to right click on Project's name-> click on the Configure->convert to maven project in the menu

Other issues

5 running the project hint could not find the main method.

A possible reason to view project-> Propertres->java build Path

See if the root directory where the current Java file is located is added to source (default is src folder)

6 appear garbled

This situation generally occurs when the MyEclipse default is to inherit the system default character set, which normally becomes GBK under Windows, but the international common character Set specification is UTF8,

This situation can be solved in two ways

Set the character set for the current directory

Project-> Propertres->resource

Modify text file encoding to UTF8

Modify the MyEclipse default character set

Windows->preference->general->editors->text editors->spelling

Modify encoding to UTF8

7JAVA8 Support

Java8 has been out for years, but support for JAVA8 in the current market environment is still not friendly, although I think the syntax of Lambda is really good (but getting started is a bit cumbersome and requires familiarity with syntax), MyEclipse for Spring 2014 only supports JAVA7, If you need to use JAVA8 to upgrade to MyEclipse 2015 GA and later, of course you can also switch to idea or Eclipse camp (laughter)

That's all the content.

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.