Maven
From KevinWiki
(Difference between revisions)
Line 52: | Line 52: | ||
- | === Maven | + | === Maven Lifecycle === |
+ | |||
+ | |||
Line 176: | Line 178: | ||
*Now, the project can be imported as an existing Eclipse project with 'Import' function on Eclipse (Chose <code>Existing Projects into Workspace</code>). | *Now, the project can be imported as an existing Eclipse project with 'Import' function on Eclipse (Chose <code>Existing Projects into Workspace</code>). | ||
+ | |||
+ | |||
+ | === The Project Object Model (POM) === | ||
+ | |||
+ | |||
+ | ;<code>groupId</code> | ||
+ | :An identifier for the group, team, company, project or organisation. The convention for this is the name beginning with the reverse domain name of the organisation which develops the project. (e.g. <code>com.lckymn</code>) | ||
+ | |||
+ | ;<code>artifactId</code> | ||
+ | :An identifier of a single project belongs the the <code>groupId</code> | ||
+ | |||
+ | ;<code>version</code> | ||
+ | :The version identifier of the project release. The project in active development stage can use a special ID which is a <code>SNAPSHOT</code> (e.g. 1.1.1-SNAPSHOT). | ||
+ | |||
+ | *There cannot be more than one project with the same three <code>groupId</code>, <code>artifactId</code> and <code>version</code> identifiers. | ||
+ | |||
+ | |||
+ | ;<code>packaging</code> | ||
+ | : |
Revision as of 12:01, 5 April 2009
Contents |
Install (on Ubuntu Linux 8.04 or higher)
$ sudo apt-get install maven2
Using Maven2
Create a Project
$ mvn archetype:create -DgroupId=testappgroup -DartifactId=testproject
- Result
(pwd is /home/user/workspace).
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:create] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] [archetype:create] [WARNING] This goal is deprecated. Please use mvn archetype:generate instead [INFO] Defaulting package to group ID: testappgroup [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating OldArchetype: maven-archetype-quickstart:RELEASE [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: testappgroup [INFO] Parameter: packageName, Value: testappgroup [INFO] Parameter: package, Value: testappgroup [INFO] Parameter: artifactId, Value: testproject [INFO] Parameter: basedir, Value: /home/user/workspace [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] ********************* End of debug info from resources from generated POM *********************** [INFO] OldArchetype created in dir: /home/user/workspace/testproject [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Sun Apr 05 19:20:04 EST 2009 [INFO] Final Memory: 16M/242M [INFO] ------------------------------------------------------------------------
Maven Lifecycle
Build a Project
Integration with Eclipse
Add Maven Repository Info
-Add the Maven repository info to the Eclipse workspace.
- Close Eclipse if it is running
- Open the terminal and type the following command.
$ mvn -Declipse.workspace=/home/user/workspace eclipse:add-maven-repo
(Don't use ~ for home directory).
- Result
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [eclipse:add-maven-repo] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] [eclipse:add-maven-repo] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Sun Apr 05 16:37:42 EST 2009 [INFO] Final Memory: 16M/292M [INFO] ------------------------------------------------------------------------
- Then
M2_REPO
can be found from
Preferences -> Java -> Classpath Variables
- If the mvn command is executed while Eclipse is running, restart the Eclipse.
Add Eclipse Metadata to Non-Eclipse Project
- Move to the project and run the
maven eclipse:eclipse
$ cd /home/user/workspace/testproject $ mvn eclipse:eclipse
- Result
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] ------------------------------------------------------------------------ [INFO] Building testproject [INFO] task-segment: [eclipse:eclipse] [INFO] ------------------------------------------------------------------------ [INFO] Preparing eclipse:eclipse [INFO] No goals needed for project - skipping [INFO] [eclipse:eclipse] [INFO] Using Eclipse Workspace: /home/user/workspace [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaults suffice [INFO] Wrote Eclipse project for "testproject" to /home/user/workspace/testproject. [INFO] Sources for some artifacts are not available. Please run the same goal with the -DdownloadSources=true parameter in order to check remote repositories for sources. List of artifacts without a source archive: o junit:junit:3.8.1 Javadoc for some artifacts is not available. Please run the same goal with the -DdownloadJavadocs=true parameter in order to check remote repositories for javadoc. List of artifacts without a javadoc archive: o junit:junit:3.8.1 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Sun Apr 05 19:56:21 EST 2009 [INFO] Final Memory: 16M/243M [INFO] ------------------------------------------------------------------------
- To download the source code and the javadoc of the junit mentioned above, run the following command.
(Optional)
$ mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
- Result
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] ------------------------------------------------------------------------ [INFO] Building testproject [INFO] task-segment: [eclipse:eclipse] [INFO] ------------------------------------------------------------------------ [INFO] Preparing eclipse:eclipse [INFO] No goals needed for project - skipping [INFO] [eclipse:eclipse] [INFO] Using Eclipse Workspace: /home/user/workspace [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaults suffice [INFO] Wrote Eclipse project for "testproject" to /home/user/workspace/testproject. [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Sun Apr 05 20:06:13 EST 2009 [INFO] Final Memory: 17M/292M [INFO] ------------------------------------------------------------------------
- Now, the project can be imported as an existing Eclipse project with 'Import' function on Eclipse (Chose
Existing Projects into Workspace
).
The Project Object Model (POM)
groupId
- An identifier for the group, team, company, project or organisation. The convention for this is the name beginning with the reverse domain name of the organisation which develops the project. (e.g.
com.lckymn
)
artifactId
- An identifier of a single project belongs the the
groupId
version
- The version identifier of the project release. The project in active development stage can use a special ID which is a
SNAPSHOT
(e.g. 1.1.1-SNAPSHOT).
- There cannot be more than one project with the same three
groupId
,artifactId
andversion
identifiers.
packaging