在過去的教學中,使用 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中,你可以現在就開始你的開發。