Plugin Configuration

What are the intern plugin parameter?
project
The project to build. Type: org.apache.maven.project.MavenProject, @required, @readonly, default:${project}
artifacts
All the dependencies including transient dependencies. Type: java.util.Collection, @required, @readonly, default:${project.artifacts}
buildDirectory
The directory for the resulting file. Type: java.io.File, @required, @readonly, default:${project.build.directory}
mainJarFilename
Name of the main JAR. Type: java.lang.String, @required, @readonly, default:${project.build.finalName}.jar

What are the useable plugin parameter?
mainClass
The application main class that one-jar should activate. Type: java.lang.String, default:${one-jar.main.class}
onejarArchivURL(removed parameter)
URL of one-jar implementations archiv to download. Type: java.lang.String, @required default-value="http://sourceforge.net/projects/one-jar/files/one-jar/one-jar-0.97/one-jar-boot-0.97.jar/download"
onejarArtifactName(removed parameter)
The name of one-jar library file such as "one-jar-boot-0.97.jar". The plugin will be fail if this file is not specified at the dependencies! Type: java.lang.String, @required default-value="one-jar-boot-0.97.jar"
onejarLicenseURL
URL of one-jar license file to download. Type: java.lang.String, @required default-value="http://one-jar.sourceforge.net/one-jar-license.txt"
fileNameMap
Map to define a mapping of library names to target names. The mapping is executed after the stripVersion parameters is executed. Type: java.util.Map, no default
stripVersion
Strip the version numbers of all libraries. Type: boolean, default:false
implementationVersion
Implementation Version of the jar. This is written to the manifest Defaults to the build's version. Type: java.lang.String, @required, default:${project.version}
finalFileName
Name of the generated JAR. Type: java.lang.String, @required, default: ${project.build.finalName}.one-jar.jar

Which maven repository contains the 1jar-maven-plugin?

This plugin is not available in the standard maven repository! But you can download it via the following repository entry in your pom.xml

For Download Plugin from Sourceforge, please add this to your pom.xml

	<pluginRepositories>
		<pluginRepository>
			<id>sourceforge</id>
			<name>SF Maven Plugin Repository</name>
			<url>http://sf-mvn-plugins.svn.sourceforge.net/svnroot/sf-mvn-plugins/_m2-repo</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>
               

You should be use the wagon-http-sourceforge extension to download it in your pom.xml

   <repositories>
     <repository>
       <id>sourceforge-svn</id>
       <name>SF Maven Plugin SVN Repository</name>
       <url>http://sf-mvn-plugins.svn.sourceforge.net/svnroot/sf-mvn-plugins/_m2-repo/trunk</url>
   </repository>
  </repositories>
                
    <build>
		<extensions>
			<extension>
				<groupId>net.sf.maven.plugins</groupId>
				<artifactId>wagon-http-sourceforge</artifactId>
				<version>0.4</version>
			</extension>
		</extensions>
		:
   </build>	
                
               

Example to use the 1jar-maven-plugin

How can i use ICE JNI with 1jar-maven-plugin?

  1. Download the zip from http://www.trustice.com/java/jnireg/
  2. Extract the files: ICE_JNIRegistry.dll and registry.jar
  3. Add the files to your local maven repository, like this:

    mvn install:install-file \
    -DgroupId=com.ice -DartifactId=registry -Dversion=3.1.3 -Dpackaging=jar -Dfile=registry.jar
    						
    mvn install:install-file \
    -DgroupId=com.ice -DartifactId=ICE_JNIRegistry -Dversion=3.1.3	-Dpackaging=dll -Dfile=ICE_JNIRegistry.dll
    						

    This will build the following structure in the local m2 repository.

    m2\com\ice\registry\3.1.3\registry-3.1.3.jar
    m2\com\ice\ICE_JNIRegistry\3.1.3\ICE_JNIRegistry-3.1.3.dll
    						

    Download and install the one-jar file to your local maven repository.

    <build>
     <plugins>						
      <plugin>
        <groupId>net.sf.maven.plugins</groupId>
        <artifactId>jar-install-plugin</artifactId>
        <executions>
         <execution>
          <goals>
            <goal>install</goal>
         </goals>
          <configuration>
           <downloads>
            <downloadArtifact>
       <url>http://sourceforge.net/projects/one-jar/files/one-jar/one-jar-0.97/one-jar-boot-0.97.jar/download</url>
             <groupId>com.simontuffs.onejar</groupId>
             <artifactId>one-jar-boot</artifactId>
             <version>0.97</version>
           </downloadArtifact>
          </downloads>
         </configuration>
        </execution>
      </executions>
     </plugin>
      :
    </plugins>          
    </build>         
    						

    In a project you can use the archives as dependency. Attention pleas you need one-jar dependency in your porject. Because the one-jar will be part of your target jar.

    <dependencies>
    	<dependency>
    		<groupId>com.ice</groupId>
    		<artifactId>registry</artifactId>
    		<version>3.1.3</version>
    		<type>jar</type>
    		<scope>compile</scope>
    	</dependency>
    	<dependency>
    		<groupId>com.ice</groupId>
    		<artifactId>
    			ICE_JNIRegistry
    		</artifactId>
    		<version>3.1.3</version>
    		<type>dll</type>
    		<scope>compile</scope>
    	</dependency>
        <dependency>
            <groupId>com.simontuffs.onejar</groupId>
            <artifactId>one-jar-boot</artifactId>
            <version>0.97</version>
            <scope>runtime</scope>
       </dependency>	
    </dependencies>
    						
    If you want all put together in one jar so it does not work because the libraries are not in the classpath of your main class. Now you can use the onejar technology of bootstrap classloader for libs wich are located in a jar. 1jar-maven-plugin will help todo this!
  4. You can use the 1jar-maven-plugin as following:
    <build>
         <plugins>
                <plugin>
                    <groupId>net.sf.maven.plugins</groupId>
                    <artifactId>1jar-maven-plugin</artifactId>
                    <version>0.2</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>1jar</goal>
                           </goals>
                            <configuration>
                                <mainClass>
                                    info.thomas_michel.lib.win.Main
                               </mainClass>
                                
                                <stripVersion>false</stripVersion>
                                <fileNameMap>
                                    <ICE_JNIRegistry-3.1.3.dll>
                                        ICE_JNIRegistry.dll
                                   </ICE_JNIRegistry-3.1.3.dll>
                               </fileNameMap>
                           </configuration>
                       </execution>
                   </executions>
              </plugin>
       </plugins>
    </build>
    					
    Change the main class to your main class!
  5. This command
    mvn clean package
    will build your jar:
    • Where your classes are bundled in a jar in the folder main
    • The dll located in the folder binlibs with name ICE_JNIRegistry.dll
    • And the registry.jar is located in the folder lib.
    • The manifest main class will refer to the bootclass of onejar and the One-Jar-Main-Class entry will refer to your main class.
    Now it works fine :-)

Known bugs of Plugin

Wich bugs are known?
  • The stripVersion parameter stripped the tail of fileName after the last "-". So if you use a -SNAPSHOT or -beta version only the word SNAPSHOT or beta will be removed. The reason is a very simple algorithm. I think at the moment none complex algorithms is needed.