java configuration MyEclipse Maven environment implementation steps

  • 2020-05-19 04:48:42
  • OfStack

java configures the MyEclipse Maven environment

Although most of my projects have moved to Idea, I still routinely click on MyEclipse when writing small test programs. I used to download the jar package and then import build path when using the third side library. However, it seems that it is more convenient to configure maven dependencies in idea, so I also want to use pom.xml to import the dependencies in MyEclipse.

The environment

Myeclipse for spring 2014
JRE 8
Maven 3.3.3(although MyEclipse comes with mvn plug-in, I have installed mvn before and do not know which one is used in the intermediate process)

Without much introduction to the mvn functionality and pom.xml format, let's go straight to Ask & & Answer link

Error: pom.xml format is incorrect


<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     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 contains all the necessary elements,

- xml head
-project property information
-modelVersion
- groupId, artifactId and version of the product

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

-groupid
-artifactId
-version

The element is placed in the dependency tag and included in the dependencies tag

2. I don't know how to fill in the dependency profile of the package I depend on

There are several websites on the web that search for maven configuration information

I use this a lot now

http://mvnrepository.com/

What do you need to search directly? The success rate of multiple keyword searches is relatively high. For example, com.google.gson is divided into com.google and gson

3. What if you fill in the dependencies but still report an error that you cannot download

For example, depending on the package json lib, we know that we need to fill in the following information through the search, but we cannot use it if we directly put pom.xml


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

As you can see from other sources, this jar package has other dependencies and can only be used in the case of jdk5, so if the current version of jdk is different, then it cannot be downloaded, so we need to configure it as follows


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

This information can only be resolved by looking up the maven dependency of the specified package on the Internet, and there is no general solution.

4. I have configured pom.xml, so how do we import these jar dependencies

In MyEclipse there is difference between ordinary and maven projects, if you want to use maven manage dependencies and generate the products, you need to build a maven project, but the operation of engineering operation in idea are entirely different with us, this and we also understand there is a big discrepancy (I need maven just help me download the dependent jar package, other cases I don't need him).

Here is an alternative solution. If we had a normal project, now we need to use mvn to manage the dependencies, we can now convert the original project into maven project, and then use Debug As- > Maven Install way to install the library files. Once the transformation is complete, we can still compile the export file in the same way as before, except that we can add dependencies via pom.xml.

The way to do this is to right click on project's name - > Click Configure- in the right - click menu > convert to maven project

Other problems

The main method could not be found when running the project.

See project - for one possible reason > propertres- > Java build path

See if you can add the current Java file to the source root (the default is the src folder)

6 garbled codes appear

This situation usually occurs when MyEclipse defaults to the inherited system default character set. This character set usually becomes GBK under windows, but the international common character set specification is UTF8.

This situation can be resolved 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

7 java8 support

java8 has been out for several years, but the support for java8 is still not friendly in the current market environment. Although I think the grammar of lambda is really good (but it is a little difficult to get started and you need to be familiar with the grammar), Myeclipse for Spring 2014 only supports java7. If you need to use java8, you need to upgrade to MyEclipse 2015 GA and later versions. You can also switch to idea or eclipse. (laughter)

That's all

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


Related articles: