Archive for May, 2008
Install an external jar into local Maven repository
Sunday, May 4th, 2008Sometimes, you project will have dependency on a jar which is not in official maven repository, and maybe it is propriety jar file which will never be part of maven repository. In this case, you have to put it to your local repository your self to solve the dependency.
There is a install plug in to do this job, which is something like:
mvn install:install-file -DgroupId=<your_group_name> \ -DartifactId=<your_artifact_name> \ -Dversion=<snapshot> \ -Dfile=<path_to_your_jar_file> \ -Dpackaging=jar \ -DgeneratePom=true
For example, you want to install the danga’s memcached client plugin, you can do:
mvn install:install-file -DgroupId=com.danga \ -DartifactId=memcached \ -Dversion=2.0.1 \ -Dfile=java_memcached-release_2.0.1.jar \ -Dpackaging=jar \ -DgeneratePom=true
This will add the memcache jar into your local Maven2 repository under groupId com.danga and artifactId memcached, you can then edit your pom.xml adding this dependency.
However, the maven eclipse can not recognize it since it always search from public repository.
Maven Project Layout
Saturday, May 3rd, 2008src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project’s license
README.txt Project’s readme
Maven release
Saturday, May 3rd, 2008You can use maven release plugin to make your release job much easier. it will automatically test build the project and run all unit test. After that, it will create a tag for you, and then update the current snapshot version to a newer one.
For using the release plugin, you will need to set up the scm info first:
<project>
...
<scm>
<connection>...</connection>
<developerConnection>...</developerConnection>
<url>...</url>
</scm>
The ‘connection’ tag is for read only checkout, and ‘developerConnection’ is with commit permission.
The value of them will look like: ’scm:svn:http://….’, given you are using SVN/Webdav as your SCM system.
After that, you can use: ‘mvn release:prepare’ for preparing your release. And you can use ‘mvn release:perform’ for doing the release.
Please note that if you don’t have a repository set up, the release:perform will fail. That’s okay is you don’t really need to release it by repository. You can just delete those 2 generated release property file.
How to indicate the java compiler version and target version
Saturday, May 3rd, 2008By default, the maven will use the compiler source check level to 1.3 and target version to 1.1 for maximum artifact compatibility. However, in most of your project, you don’t need such compatibility. In contrast, you will want to use more recently language features: like assertion, generic type of container, and so on. You can do that be indicate the compiler source and target requirement.
First, from Eclipse IDE, select “maven – add plugin”, add the maven-compiler-plugin, the lastest version should be 2.02. This will add some elements to you pom.xml like:
...
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
</plugins>
</build>
...
you can add attibutes after version, like:
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
This will set the source check and target check version to jre 6.0. You will notice that although sun has change this naming scheme from 1.x to x.0 from jre 5.0 on, but maven still using 1.x scheme.
Use log4j-1.2.14 instead of 1.2.15 in Maven Project
Saturday, May 3rd, 2008Get Maven project from svn to Eclipse
Saturday, May 3rd, 2008When you put a maven project under source control like SVN, you don’t have to check in the IDE’s project file. What you will do is check in the pom.xml and the source folder. That is enough for you to rebuild the project.
If you want to continue work on this project on your favorite IDE (like Eclipse) again, you can simply choose “File-import” and from the dialog box, select “Other – Check out Maven Project from scm” and the locate you source repository in the following wizard, and you are good to go. The Maven plugin will generate the project file for you according to pom file settings.
