Java configuration MyEclipse Maven environment specific implementation steps
Java to configure MyEclipse Maven environment
Although most of my projects have been moved to idea, I still habitually click MyEclipse when writing some small test programs. Before using the third-party library, I used to download the jar package and then import it with build path, but it seems more convenient to configure Maven dependency in idea, so I also want to use POM in MyEclipse XML to import dependencies. I encountered some problems in the process of trying. Here are the methods to solve these problems.
environment
Myeclipse for spring 2014 JRE 8 Maven 3.3. 3 (although MyEclipse comes with its own MVN plug-in, I installed MVN before, and I don't know which intermediate process is used)
For the function of MVN and POM The format of XML will not be introduced too much. Let's directly cut into the link of ask & & answer
1. Error report: POM The XML format is incorrect
This is the simplest POM XML contains all the necessary elements,
-XML header - Project attribute information - modelversion - groupid, artifactid and version of the artifact
When configuring a dependency (the jar package you depend on), you need to include at least three elements
-groupid -artifactId -version
And put the element in the dependency tag and include it in the dependencies tag
2. I don't know how to fill in the dependent configuration items of the package I depend on
There are some websites on the Internet to search for Maven configuration information
I often use this now
http://mvnrepository.com/
What you need to search directly is OK. You can use multiple keywords for many times, and the success rate is relatively high, such as com google. Gson sub com Google and gson search, and finally you will get the results you want
3. What if you fill in the dependency but still report an error that you can't download it
For example, relying on the JSON lib package, we know that we need to fill in the following information through search, but if we put it directly into POM XML is unusable
We can know from other ways that this jar package has other dependencies and can only be used in the case of jdk5. Therefore, if the current JDK version is different, it cannot be downloaded, so we need to configure it in the following form
This kind of information can only be solved by finding the Maven dependency of the specified package on the Internet. There is no common solution.
4. I have configured POM XML, so how do we import these jar dependencies
In MyEclipse, there are differences between ordinary projects and Maven projects. If you want to use Maven to manage dependencies and generate artifacts, you need to establish a maven project, but this operation project is very different from our operation in idea, This is also very different from our understanding (I need Maven to help me download the dependent jar package. In other cases, I don't need him).
Here is an alternative solution. If there was an ordinary project, now we need to use MVN to manage some dependencies. At this time, we can convert the original project into Maven project, and then install the library file by using debug as - > Maven install. After the conversion is completed, we can still compile the export file in the previous way. The difference from the previous one is that we can use POM XML to add dependencies.
The conversion method is to right-click the name of the project - > click Configure - > Convert to Maven project in the right-click menu
Other issues
5. The main method cannot be found when running the project prompt.
One possible reason is to check project - > properties - > java build path
See whether to add the root directory of the current java file to the source (SRC folder by default)
6. Garbled code
This situation generally occurs in MyEclipse. By default, it inherits the system default character set. This character set will generally become GBK under windows, but the international common character set specification is utf8,
This situation can be solved in two ways
Sets the character set for the current directory
project -> propertres->resource
Modify text file encoding to utf8
Modify MyEclipse default character set
windows->preference->general->editors->text editors ->spelling
Modify encoding to utf8
7java8 support
Java8 has been out for several years, but the support for java8 in the current market environment is still not friendly, Although I think lambda's syntax is really good (but it's really troublesome to get started and need to be familiar with the syntax), MyEclipse for spring 2014 only supports java7. If you need to use java8, you need to upgrade to MyEclipse 2015 GA and later. Of course, you can also switch to idea or eclipse camp (laughter)
That's all
Thank you for reading, hope to help you, thank you for your support to this site!