Maven New Projects Command Line

Manual Steps (Command Line)

1. cd to the directory where the project will be created. In this example, I'm setting up com.jettmarks.base. The appropriate location for the MavenWorkspace is D:\data\java\projects. The artifactId parameter below will create a directory of that name below this directory.
2. Run this command to create the directory structure for the new project:

mvn archetype:generate -DgroupId=com.jettmarks.base -DartifactId=base

A whole bunch of things get downloaded the first time and eventually you will be prompted for an archtype.
(NOTE: The tutorial uses the goal "create" instead of "generate". The "create" goal was recently deprecated.)
1. I chose archetype #15 (maven-archetype-quickstart) for a simple jar file, but you may find something else more appropriate.
2. The default snapshot version should be fine.

Only required for first Eclipse project

1. Make sure Eclipse is pointed to the new workspace D:\data\java\workspace. If you needed to open Eclipse to be sure, shut it back down for the next step.
2. Execute the following command:

mvn -Declipse.workspace=D:\data\java\workspace eclipse:add-maven-repo

Eclipse can now be brought up to check that the M2_REPO classpath variable had been added. You can add the M2_REPO classpath variable manually if you need to. Asa matter of fact, I have had this work once out of three tries. The last time, I had to edit the file ./.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs manually because it wasn't accessible from the Build Config or preferences within Eclipse.

Generate .project and .classpath files for Eclipse

1. Execute the following to create the Eclipse files:

cd base; mvn eclipse:eclipse

There should now be a .classpath and .project file in the projects/base directory.
2. Start Eclipse and import the project using File -> Import and choosing "Existing Projects". There is no need to copy the files into the workspace.

Attach m2eclipse for dependency management

* Right click the project and select 'Maven -> Enable Dependency Management'

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License