在过去的教程中,使用 Maven 创建了一个Java项目,但是这个项目不能导入到Eclipse IDE中,因为它不是 Eclipse 风格的项目。
这里有一个指南,向您演示如何转换 Maven 生成 Java 项目为 Eclipse 支持格式的项目。
这真的很容易做到这一点。浏览到 Java 项目文件夹,其中 pom.xml 文件被重写。并发出以下命令:
C:\worksp>mvn archetype:generate -DgroupId=com.yiibai -DartifactId=Yiibaicor
[INFO] -------------------------------------------------------------------------
---
[INFO] Using following parameters for creating project from Old (1.x) Archetype:
maven-archetype-quickstart:1.1
[INFO] -------------------------------------------------------------------------
---
[INFO] Parameter: basedir, Value: C:\worksp
[INFO] Parameter: package, Value: com.yiibai
[INFO] Parameter: groupId, Value: com.yiibai
[INFO] Parameter: artifactId, Value: Yiibaicor
[INFO] Parameter: packageName, Value: com.yiibai
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\worksp\Yiibaicor
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:37 min
[INFO] Finished at: 2015-10-27T20:37:00+08:00
[INFO] Final Memory: 16M/185M
[INFO] ------------------------------------------------------------------------
看一个完整的例子:
C:\worksp>cd Yiibaicor
C:\worksp\Yiibaicor>mvn eclipse:eclipse
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Yiibaicor 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.10:eclipse (default-cli) > generate-resources
@ Yiibaicor >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.10:eclipse (default-cli) < generate-resources
@ Yiibaicor <<<
[INFO]
[INFO] --- maven-eclipse-plugin:2.10:eclipse (default-cli) @ Yiibaicor ---
[INFO] Using Eclipse Workspace: null
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAI
ER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "Yiibaicor" to C:\worksp\Yiibaicor.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.737 s
[INFO] Finished at: 2015-10-27T20:39:15+08:00
[INFO] Final Memory: 13M/114M
[INFO] ------------------------------------------------------------------------
在此之后,你会发现创建了两个新文件 - “.classpath”和“.project”。这两个文件都为 Eclipse IDE 所创建。
File : .classpath
<?xml version="1.0" encoding="UTF-8"?>
<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="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
</classpath>
File : .project
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Yiibaicor</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>
现在,将它导入到 Eclipse IDE中,请按以下步骤操作:
在Eclipse IDE,菜单栏 , File -> Import… -> General -> Existing Projects into Workspace -> 选择根目录(选择项目文件夹中) - >完成。
你的Maven生成的Java项目导入到Eclipse IDE中,你可以现在就开始你的开发。
转载请注明出处: http://www.julyme.com/20161219/64.html
打赏一个呗~~(微信)
Julyme
感觉还行吧。
Julyme的IT技术分享