In order to create a new maven project called
MyProject run the following command:
mvn archetype:create -DgroupId=fs.work -DartifactId=MyProjectThis will create a new directory called
MyProject with a pom.xml and the following tree structure:
MyProject |-->pom.xml |-->src | |-->main | | |-->java | | | |-->fs | | | | |-->work | | | | | |-->App.java | |-->test | | |-->java | | | |-->fs | | | | |-->work | | | | | |-->AppTest.javaThe pom file looks like this:
Creating sub-modules4.0.0 fs.work MyProject jar 1.0-SNAPSHOT MyProject http://maven.apache.org junit junit 3.8.1 test
If you need to create sub-modules within your project, you need to change the
packaging in the pom file (i.e. the "super" pom), to pom. Then, from within the MyProject directory issue the following commands to create sub-modules:
mvn archetype:create -DgroupId=fs.work -DartifactId=MyProjectWeb -Dpackaging=war mvn archetype:create -DgroupId=fs.work -DartifactId=MyProjectModule1 -Dpackaging=jarThis creates the sub-modules and the directory tree now looks like this:
MyProject |-->pom.xml |-->src | |-->main | | |-->java | | | |-->fs | | | | |-->work | | | | | |-->App.java | |-->test | | |-->java | | | |-->fs | | | | |-->work | | | | | |-->AppTest.java |-->MyProjectModule1 | |-->pom.xml | |-->src | | |-->main | | | |-->java | | | | |-->fs | | | | | |-->work | | | | | | |-->App.java | | |-->test | | | |-->java | | | | |-->fs | | | | | |-->work | | | | | | |-->AppTest.java |-->MyProjectWeb | |-->pom.xml | |-->src | | |-->main | | | |-->java | | | | |-->fs | | | | | |-->work | | | | | | |-->App.java | | |-->test | | | |-->java | | | | |-->fs | | | | | |-->work | | | | | | |-->AppTest.javaThe pom file for
MyProjectModule1 contains a reference to the parent and looks like this:
Deploying a jar to the repositoryMyProject fs.work 1.0-SNAPSHOT 4.0.0 fs.work MyProjectModule1 MyProjectModule1 1.0-SNAPSHOT http://maven.apache.org junit junit 3.8.1 test
If you have a jar file called
myarchive.jar which you want to upload to your maven repository, use the following command:
mvn deploy:deploy-file -Durl=scp://hostname/dir/to/maven -DrepositoryId=fs.repo -Dfile=myarchive.jar -DgroupId=fs.work -DartifactId=myarchive -Dversion=1.0 -Dpackaging=jarThis will create
dir/to/maven/fs/work/myarchive/1.0/myarchive-1.0.jar in the maven repository.
Creating a dependencyTo create a dependency on
myarchive.jar, add the following dependency to your pom:
Generating Eclipse .project and .classpath filesfs.work myarchive 1.0
Use the following command:
mvn eclipse:eclipseSkipping tests
To skip tests use the property
maven.test.skip=true.
mvn -Dmaven.test.skip=true installRelease a project
Two commands must be invoked, in the following order:
mvn release:prepare mvn release:performOther commands
mvn install mvn clean mvn compile mvn jar:jar
Your mvn commands seems a bit long (without scrolling). I think you may improve it by using a JS code formatter such as Prettify or SyntaxHightlighter
ReplyDelete:-)
I have compiled a mini guide command reference for maven. You can see it here http://www.shankh.com/2009/07/12/maven-commands-reference-mini-guide/
ReplyDelete