转自: http://www.xuebuyuan.com/1297046.html
在前一篇文章中,我们使用maven创建了一个java 项目, 但是这个项目不能导入 Eclipse IDE, 因为它不是 Eclipse style的项目。
Here’s a guide to show you how to convert the Maven generated Java project to Eclipse supported style project.
is placed. And issue this command :
- mvn eclipse:eclipse
- C:Usersadminhenrycublog>mvn eclipse:eclipse
- [INFO] Scanning for projects...
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclips
- e-plugin/maven-metadata.xml
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse
- -plugin/maven-metadata.xml (680 B at 0.2 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclips
- e-plugin/2.8/maven-eclipse-plugin-2.8.pom
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse
- -plugin/2.8/maven-eclipse-plugin-2.8.pom (12 KB at 3.7 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin
- s/17/maven-plugins-17.pom
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins
- /17/maven-plugins-17.pom (13 KB at 8.6 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclips
- e-plugin/2.8/maven-eclipse-plugin-2.8.jar
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse
- -plugin/2.8/maven-eclipse-plugin-2.8.jar (202 KB at 5.4 KB/sec)
- [INFO]
- [INFO] ------------------------------------------------------------------------
- [INFO] Building henrycublog 1.0-SNAPSHOT
- [INFO] ------------------------------------------------------------------------
- [INFO]
- [INFO] >>> maven-eclipse-plugin:2.8:eclipse (default-cli) @ henrycublog >>>
- [INFO]
- [INFO] <<< maven-eclipse-plugin:2.8:eclipse (default-cli) @ henrycublog <<<
- [INFO]
- [INFO] --- maven-eclipse-plugin:2.8:eclipse (default-cli) @ henrycublog ---
- Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-interactiv
- ity-jline/1.0-alpha-5/plexus-interactivity-jline-1.0-alpha-5.pom
- Downloaded: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-interactivi
- ty-jline/1.0-alpha-5/plexus-interactivity-jline-1.0-alpha-5.pom (772 B at 0.7 KB
- /sec)
- Downloading: http://repo1.maven.org/maven2/jline/jline/0.9.1/jline-0.9.1.pom
- Downloaded: http://repo1.maven.org/maven2/jline/jline/0.9.1/jline-0.9.1.pom (145
- B at 0.1 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-archiver/2.2/m
- aven-archiver-2.2.pom
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/maven-archiver/2.2/ma
- ven-archiver-2.2.pom (2 KB at 1.3 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-shared-
- components/3/maven-shared-components-3.pom
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-shared-c
- omponents/3/maven-shared-components-3.pom (2 KB at 2.0 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-resources/
- 1.0-alpha-7/plexus-resources-1.0-alpha-7.pom
- Downloaded: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-resources/1
- .0-alpha-7/plexus-resources-1.0-alpha-7.pom (2 KB at 1.3 KB/sec)
- Downloading: http://repo1.maven.org/maven2/biz/aQute/bndlib/0.0.145/bndlib-0.0.1
- 45.pom
- Downloaded: http://repo1.maven.org/maven2/biz/aQute/bndlib/0.0.145/bndlib-0.0.14
- 5.pom (886 B at 0.7 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-osgi/0.
- 2.0/maven-osgi-0.2.0.pom
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-osgi/0.2
- .0/maven-osgi-0.2.0.pom (2 KB at 2.0 KB/sec)
- Downloading: http://repo1.maven.org/maven2/biz/aQute/bndlib/0.0.203/bndlib-0.0.2
- 03.pom
- Downloaded: http://repo1.maven.org/maven2/biz/aQute/bndlib/0.0.203/bndlib-0.0.20
- 3.pom (886 B at 0.7 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/eclipse/core/resources/3.3.0-v200
- 70604/resources-3.3.0-v20070604.pom
- Downloaded: http://repo1.maven.org/maven2/org/eclipse/core/resources/3.3.0-v2007
- 0604/resources-3.3.0-v20070604.pom (2 KB at 1.1 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-interactiv
- ity-jline/1.0-alpha-5/plexus-interactivity-jline-1.0-alpha-5.jar
- Downloading: http://repo1.maven.org/maven2/jline/jline/0.9.1/jline-0.9.1.jar
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-archiver/2.2/m
- aven-archiver-2.2.jar
- Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-resources/
- 1.0-alpha-7/plexus-resources-1.0-alpha-7.jar
- Downloading: http://repo1.maven.org/maven2/biz/aQute/bndlib/0.0.145/bndlib-0.0.1
- 45.jar
- Downloaded: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-interactivi
- ty-jline/1.0-alpha-5/plexus-interactivity-jline-1.0-alpha-5.jar (6 KB at 5.4 KB/
- sec)
- Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-osgi/0.
- 2.0/maven-osgi-0.2.0.jar
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-osgi/0.2
- .0/maven-osgi-0.2.0.jar (13 KB at 6.8 KB/sec)
- Downloading: http://repo1.maven.org/maven2/org/eclipse/core/resources/3.3.0-v200
- 70604/resources-3.3.0-v20070604.jar
- Downloaded: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-resources/1
- .0-alpha-7/plexus-resources-1.0-alpha-7.jar (23 KB at 5.1 KB/sec)
- Downloaded: http://repo1.maven.org/maven2/org/apache/maven/maven-archiver/2.2/ma
- ven-archiver-2.2.jar (10 KB at 1.5 KB/sec)
- Downloaded: http://repo1.maven.org/maven2/biz/aQute/bndlib/0.0.145/bndlib-0.0.14
- 5.jar (112 KB at 6.5 KB/sec)
- Downloaded: http://repo1.maven.org/maven2/jline/jline/0.9.1/jline-0.9.1.jar (46
- KB at 2.6 KB/sec)
- Downloaded: http://repo1.maven.org/maven2/org/eclipse/core/resources/3.3.0-v2007
- 0604/resources-3.3.0-v20070604.jar (663 KB at 6.5 KB/sec)
- [INFO] Using Eclipse Workspace: null
- [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAIN
- ER
- [INFO] Not writing settings - defaults suffice
- [INFO] Wrote Eclipse project for "henrycublog" to C:Usersadminhenrycublog.
- [INFO]
- [INFO] ------------------------------------------------------------------------
- [INFO] BUILD SUCCESS
- [INFO] ------------------------------------------------------------------------
- [INFO] Total time: 2:48.142s
- [INFO] Finished at: Wed Nov 09 11:31:54 CST 2011
- [INFO] Final Memory: 8M/58M
- [INFO] ------------------------------------------------------------------------
- C:Usersadminhenrycublog>
Note
If this is your first time to run this command, it may take some time to download all required dependency to convert your project to Eclipse style project.
After that, you will notice two new files are created – “.classpath” and “.project“. Both files are created for Eclipse IDE.
File : .classpath
- <classpath>
- <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
- <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
- <classpathentry kind="output" path="target/classes"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- </classpath>
Wait, M2_REPO !?
Did you notice a “M2_REPO” classpath variable is generated? For first time, you have to add
this M2_REPO classpath variable to your Eclipse IDE. Otherwise, Eclipse will raise error about your imported project later.
当然,如果你已经安装了maven eclipse插件,那就很简单了。window>Preferences>Maven>Installations>Add(添加你的maven安装位置)
如果你没有安装Maven插件,按以下方法添加M2_REPO:
Define and add M2_REPO classpath variable manually to Eclipse IDE. Follow below steps :
- Eclipse IDE, menu bar
- Select Window > Preferences
- Select Java > Build Path > Classpath Variables
- Click on the new button > defined a new M2_REPO variable and point it to your local Maven repository
Done.
File : .project
- <projectDescription>
- <name>henrycublog</name>
- <comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
- <projects/>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
- </projectDescription>
3. Import into Eclipse IDE
Now, import it into Eclipse IDE, follow below steps :
In Eclipse IDE, menu bar , File -> Import… -> General -> Existing Projects into Workspace -> select root directory (select your project folder) -> Done.