Maven
From KevinWiki
(Difference between revisions)
(New page: Category:Project Management == Install (on Ubuntu Linux 8.04 or higher) == <pre> $ sudo apt-get install maven2 </pre> == Using Maven2 == === Create a Project === <pre> mvn archety...) |
|||
Line 3: | Line 3: | ||
== Install (on Ubuntu Linux 8.04 or higher) == | == Install (on Ubuntu Linux 8.04 or higher) == | ||
<pre> | <pre> | ||
- | $ sudo apt-get install maven2 | + | $ sudo apt-get install maven2 |
</pre> | </pre> | ||
Line 12: | Line 12: | ||
<pre> | <pre> | ||
- | mvn archetype:create -DgroupId= | + | $ mvn archetype:create -DgroupId=testappgroup -DartifactId=testproject |
</pre> | </pre> | ||
+ | *Result | ||
+ | (pwd is /home/user/workspace). | ||
+ | <pre> | ||
+ | [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] ------------------------------------------------------------------------ | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | === Maven Life Cycle === | ||
=== Build a Project === | === 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. | ||
+ | <pre> | ||
+ | $ mvn -Declipse.workspace=/home/user/workspace eclipse:add-maven-repo | ||
+ | </pre> | ||
+ | (Don't use ~ for home directory). | ||
+ | |||
+ | *Result | ||
+ | <pre> | ||
+ | [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] ------------------------------------------------------------------------ | ||
+ | </pre> | ||
+ | |||
+ | *Then <code>M2_REPO</code> can be found from | ||
+ | <pre> | ||
+ | Preferences -> Java -> Classpath Variables | ||
+ | </pre> | ||
+ | |||
+ | *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 <code>maven eclipse:eclipse</code> | ||
+ | <pre> | ||
+ | $ cd /home/user/workspace/testproject | ||
+ | $ mvn eclipse:eclipse | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | *Result | ||
+ | <pre> | ||
+ | [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] ------------------------------------------------------------------------ | ||
+ | </pre> | ||
+ | |||
+ | *To download the source code and the javadoc of the junit mentioned above, run the following command. | ||
+ | (Optional) | ||
+ | <pre> | ||
+ | $ mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true | ||
+ | </pre> | ||
+ | |||
+ | *Result | ||
+ | <pre> | ||
+ | [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] ------------------------------------------------------------------------ | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | *Now, the project can be imported as an existing Eclipse project with 'Import' function on Eclipse (Chose <code>Existing Projects into Workspace</code>). |
Revision as of 10:13, 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 Life Cycle
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
).