Maven3 项目创建设置

来源:互联网 发布:论文表格数据来源 编辑:程序博客网 时间:2024/06/06 03:42

New Project

For this example I will be using Eclipse for my IDE.

  1. Download Eclipse IDE for Java EE Developers from http://www.eclipse.org/downloads/
  2. Unzip the contents in your root Eclipse folder.  In my case I unzipped it in c:/java/eclipse
  3. Run the ‘eclipse.exe’ in [eclipse root]/eclipse
  4. Select a workspace location for Eclipse to store your projects.  In my case I used the default location

    m3-02

  5. Click on the ‘Workbench’ icon

    m3-03[1]

  6. Select Help -> Install New Software

    m3-04[1]

  7. Click the ‘Add…’ button
  8. Name: m2eclipse
  9. Location: http://m2eclipse.sonatype.org/sites/m2e
  10. Click ‘OK’

    m3-05

  11. Check the ‘Maven Integration for Eclipse’ option
  12. Click ‘Next’

    m3-06

  13. Click ‘Next >’

    m3-07

  14. Select ‘I accept the terms of the license agreements’
  15. Click ‘Finish’

    m3-08

  16. Click ‘Restart Now’

    m3-09
    m3-10

  17. Select Window -> Preferences

    m3-11

  18. Add the Maven 3 location the you installed earlier

    m3-12

  19. Create a new Maven project by selecting File -> New -> Other…

    m3-13

  20. Select Maven -> Maven Project

    m3-14

  21. Check ‘Create a simple project (skip archetype selection)’
  22. Click ‘Next >’

    m3-24

  23. Enter Project Information
    1. Enter Group Id. This is the domain where the project is hosted. For example if the ‘Awesome’ project was hosted at GitHub then the Group Id would be ‘com.github.awesome’.
    2. Enter Artifact Id. This is the name of the resulting artifact. For example if Artifact Id is ‘awesome’ and the packaging is JAR the artifact will be named ‘awesome.jar’.
    3. The version can remain 0.0.1-SNAPSHOT
    4. Select the packaging that you desire
    5. Enter a Name. This name will show up in the console when you run Maven. This will also show up in the documentation that Maven generates
    6. Enter a Description. This is used in the documentation
    7. Click ‘Next >’

    m3-16

  24. Add a dependency on JUnit. One of the best features of m2eclipse plugin is the ability to search for available dependencies.  (This feature does not work if you configure ‘M3_HOME’ instead of ‘M2_HOME’)

    m3-17

  25. Click ‘Finish’
    • src – source and resource files
    • target – compiled files, reports and generated artifacts
    • main – application/library files
    • test – test files
    • java – java files
    • resources – non java files like XML

    m3-18
    Maven’s default package structure:
    m3-19

  26. Open the pom.xml file.
  27. Add the compiler plugin so you can configure your JDK version. Search for the maven-compiler-plugin.

    m3-20

  28. For this example set the JDK version to 1.6

    m3-21

    <configuration> <source>1.6</source> <target>1.6</target> </configuration>
  29. Run ‘Maven install’ to verify that the project and environment is setup correctly

    m3-22

  30. The build was successful

    m3-23


























maven需要的jar下载
0 0
原创粉丝点击