Maven combined with Eclipse FAQ

Maven is an excellent Java project construction tool, which is very convenient to use alone. But when combined with Eclipse, it will encounter some embarrassing problems.

1. Maven dependencies are missing

Once encountered such a situation, I saw a project check from github and imported it into Eclipse. As a result, Eclipse displayed a bunch of red crosses. Right-click to find that the dependencies managed by Maven are not imported. The reason is that Eclipse does not recognize Maven's Jar. Although there is pom.xml in the project, Eclipse defaults to .classpath.

Maven has provided ready-made plug-ins, open the command line and enter the project directory to execute

mvn eclipse:eclipse 

The above command will add all dependencies in pom.xml to Eclipse's .classpath.

Of course, in addition to the initial stage, you can also right-click Eclipse and select the Maven project to import or you can manually modify the .classpath (more difficult).

If it is a brand new workspace, you need to initialize the workspace with the following command

mvn -Declipse.workspace=<eclipse workspace> eclipse:add-maven-repo

 E.g

mvn -Declipse.workspace=/home/ft/workspaces/wksp1/ eclipse:add-maven-repo

 2. Run Tomcat from Eclipse, the Maven package is not released

Sometimes this happens. The project compiles and builds in Eclipse normally, but after starting Tomcat, an error prompts classxxxxnotFound. If the project is packaged as a war and published to Tomcat, it can also run normally.

At this point, open the Tomcat release directory and find that the WEB-INF is empty. If you copy the jar manually, start tomcat again and find that the jar is gone. . . , because Tomcat will be redeployed every time it restarts.

 

Here's how to deal with it

  1. Right click on Properties of the project.
  2. Select Deployment Assembly option.
  3. Click on Add button.
  4. Select Java Build Path Entries as follows.
  5. Click on Next to get the following wizard:
  6. Select Maven Dependencies.

  7. Click on finish.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326039252&siteId=291194637