Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2529991
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: Java

2011-11-09 11:36:08

将 Maven生成的java项目转化为支持 Eclipse IDE的项目

在前一篇文章中,我们使用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.

1. mvn eclipse:eclipse
It’s really easy to do it. Navigate to your Java project folder, where pom.xml file is placed. And issue this command :

  1. mvn eclipse:eclipse
完整的运行情况,可能像这样:
  1. C:\Users\admin\henrycublog>mvn eclipse:eclipse
  2. [INFO] Scanning for projects...
  3. Downloading:
  4. e-plugin/maven-metadata.xml
  5. Downloaded: e
  6. -plugin/maven-metadata.xml (680 B at 0.2 KB/sec)
  7. Downloading:
  8. e-plugin/2.8/maven-eclipse-plugin-2.8.pom
  9. Downloaded: e
  10. -plugin/2.8/maven-eclipse-plugin-2.8.pom (12 KB at 3.7 KB/sec)
  11. Downloading:
  12. s/17/maven-plugins-17.pom
  13. Downloaded: s
  14. /17/maven-plugins-17.pom (13 KB at 8.6 KB/sec)
  15. Downloading:
  16. e-plugin/2.8/maven-eclipse-plugin-2.8.jar
  17. Downloaded: e
  18. -plugin/2.8/maven-eclipse-plugin-2.8.jar (202 KB at 5.4 KB/sec)
  19. [INFO]
  20. [INFO] ------------------------------------------------------------------------
  21. [INFO] Building henrycublog 1.0-SNAPSHOT
  22. [INFO] ------------------------------------------------------------------------
  23. [INFO]
  24. [INFO] >>> maven-eclipse-plugin:2.8:eclipse (default-cli) @ henrycublog >>>
  25. [INFO]
  26. [INFO] <<< maven-eclipse-plugin:2.8:eclipse (default-cli) @ henrycublog <<<
  27. [INFO]
  28. [INFO] --- maven-eclipse-plugin:2.8:eclipse (default-cli) @ henrycublog ---
  29. Downloading:
  30. ity-jline/1.0-alpha-5/plexus-interactivity-jline-1.0-alpha-5.pom
  31. Downloaded: i
  32. ty-jline/1.0-alpha-5/plexus-interactivity-jline-1.0-alpha-5.pom (772 B at 0.7 KB
  33. /sec)
  34. Downloading:
  35. Downloaded: (145
  36. B at 0.1 KB/sec)
  37. Downloading:
  38. aven-archiver-2.2.pom
  39. Downloaded: a
  40. ven-archiver-2.2.pom (2 KB at 1.3 KB/sec)
  41. Downloading:
  42. components/3/maven-shared-components-3.pom
  43. Downloaded: c
  44. omponents/3/maven-shared-components-3.pom (2 KB at 2.0 KB/sec)
  45. Downloading:
  46. 1.0-alpha-7/plexus-resources-1.0-alpha-7.pom
  47. Downloaded: 1
  48. .0-alpha-7/plexus-resources-1.0-alpha-7.pom (2 KB at 1.3 KB/sec)
  49. Downloading:
  50. 45.pom
  51. Downloaded: 4
  52. 5.pom (886 B at 0.7 KB/sec)
  53. Downloading:
  54. 2.0/maven-osgi-0.2.0.pom
  55. Downloaded: 2
  56. .0/maven-osgi-0.2.0.pom (2 KB at 2.0 KB/sec)
  57. Downloading:
  58. 03.pom
  59. Downloaded: 0
  60. 3.pom (886 B at 0.7 KB/sec)
  61. Downloading:
  62. 70604/resources-3.3.0-v20070604.pom
  63. Downloaded: 7
  64. 0604/resources-3.3.0-v20070604.pom (2 KB at 1.1 KB/sec)
  65. Downloading:
  66. ity-jline/1.0-alpha-5/plexus-interactivity-jline-1.0-alpha-5.jar
  67. Downloading:
  68. Downloading:
  69. aven-archiver-2.2.jar
  70. Downloading:
  71. 1.0-alpha-7/plexus-resources-1.0-alpha-7.jar
  72. Downloading:
  73. 45.jar
  74. Downloaded: i
  75. ty-jline/1.0-alpha-5/plexus-interactivity-jline-1.0-alpha-5.jar (6 KB at 5.4 KB/
  76. sec)
  77. Downloading:
  78. 2.0/maven-osgi-0.2.0.jar
  79. Downloaded: 2
  80. .0/maven-osgi-0.2.0.jar (13 KB at 6.8 KB/sec)
  81. Downloading:
  82. 70604/resources-3.3.0-v20070604.jar
  83. Downloaded: 1
  84. .0-alpha-7/plexus-resources-1.0-alpha-7.jar (23 KB at 5.1 KB/sec)
  85. Downloaded: a
  86. ven-archiver-2.2.jar (10 KB at 1.5 KB/sec)
  87. Downloaded: 4
  88. 5.jar (112 KB at 6.5 KB/sec)
  89. Downloaded: (46
  90. KB at 2.6 KB/sec)
  91. Downloaded: 7
  92. 0604/resources-3.3.0-v20070604.jar (663 KB at 6.5 KB/sec)
  93. [INFO] Using Eclipse Workspace: null
  94. [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAIN
  95. ER
  96. [INFO] Not writing settings - defaults suffice
  97. [INFO] Wrote Eclipse project for "henrycublog" to C:\Users\admin\henrycublog.
  98. [INFO]
  99. [INFO] ------------------------------------------------------------------------
  100. [INFO] BUILD SUCCESS
  101. [INFO] ------------------------------------------------------------------------
  102. [INFO] Total time: 2:48.142s
  103. [INFO] Finished at: Wed Nov 09 11:31:54 CST 2011
  104. [INFO] Final Memory: 8M/58M
  105. [INFO] ------------------------------------------------------------------------
  106. C:\Users\admin\henrycublog>
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.

2. Verify Java Project

After that, you will notice two new files are created – “.classpath” and “.project“. Both files are created for Eclipse IDE.

File : .classpath

  1. M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>

Wait, M2_REPO !?
Did you notice a “M2_REPO” classpath variable is generated? For first time, you have to . 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 :

  1. Eclipse IDE, menu bar
  2. Select Window > Preferences
  3. Select Java > Build Path > Classpath Variables
  4. Click on the new button > defined a new M2_REPO variable and point it to your local Maven repository

Done.


File : .project

  1. henrycublog
  2. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.
  3. org.eclipse.jdt.core.javabuilder
  4. org.eclipse.jdt.core.javanature

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.





谢谢访问!

阅读(3250) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~