How to use FatJar (out of Eclipse) in continuous integration server?
From what I understood, FatJar is an Ecl开发者_StackOverflow中文版ipse plugin which is based on the OSGi framework. I believe this makes it hard to use outside of an OSGi platform. Also, looking at decompiled FatJar, it seems to be requiring lots of OSGi and Eclipse classes, like org.eclipse.jdt.core.IJavaProject
and org.osgi.framework.BundleContext
, for example.
So, in front of all this, I'm wondering if there is any way to use our precious *.fatjar files with Hudson (using a script or whatever).
Any good advice is welcome! Thanks!
After more work and research, it seems that, even though FatJar is primarily an Eclipse plugin, it is possible to integrate it quite easily in continuous integration servers.
In my case, using Ant, I have found that it was possible to run the FatJar plugin outside of Eclipse using the following code (originally from this site).
<project name="FatJar MySuperDuperClass.jar (experimental)" default="main" basedir=".">
<!-- this file was created by Fat-Jar Eclipse Plug-in -->
<!-- the ANT-Export is in a very early stage, so this -->
<!-- is only experimental, ANT 1.6 or above is -->
<!-- required, feedback is always welcome: -->
<!-- http://sourceforge.net/projects/fjep -->
<!-- uncomment the following lines if using ANT outside Eclipse -->
<!--
<property name="fjepPath" value="plugins/net.sf.fjep.fatjar_0.0.31/fatjar.jar"/>
<taskdef name="fatjar.build" classname="net.sf.fjep.anttask.FJBuildTask" classpath="${fjepPath}"/>
<typedef name="fatjar.manifest" classname="net.sf.fjep.anttask.FJManifestType" classpath="${fjepPath}"/>
<typedef name="fatjar.exclude" classname="net.sf.fjep.anttask.FJExcludeType" classpath="${fjepPath}"/>
<typedef name="fatjar.jarsource" classname="net.sf.fjep.anttask.FJJarSourceType" classpath="${fjepPath}"/>
<typedef name="fatjar.filesource" classname="net.sf.fjep.anttask.FJFileSourceType" classpath="${fjepPath}"/>
-->
<!-- uncomment the above lines to use ANT outside of Eclipse -->
<target name="main">
<fatjar.build output="MySuperDuperClass.jar">
<fatjar.manifest mainclass="de.schwobeseggl.test.MySuperDuperClass"/>
<fatjar.filesource path="bin" relpath=""/>
<fatjar.jarsource file="lib/commons-cli.jar" relpath=""/>
<fatjar.jarsource file="lib/jbossall-client.jar" relpath=""/>
<fatjar.jarsource file="lib/junit.jar" relpath=""/>
<fatjar.jarsource file="lib/log4j.jar" relpath=""/>
<fatjar.jarsource file="lib/jdom.jar" relpath=""/>
</fatjar.build>
</target>
</project>
I uncommented the block of 6 lines at the beginning and it's working good. Reading the comment on top, it seems this was exported using FatJar itself, but don't know how to do this. I just adjusted this sample to my use case.
FatJar is an Eclipse plugin providing one-jar functionality. Outside of Eclipse you just use one-jar directly.
http://one-jar.sourceforge.net/
Note, that the Eclipse complication process is not easy to script. I've done it in Ant using ant4eclipse and I would recommend against it. EDIT: As of 2015 you should look into Maven projects instead of plain Eclipse.
My advice would be to look for an alternative to FatJar that works with your build tool.
- If you are using Maven, take a look at the shade plugin.
- For Ant, you can do the job with the appropriate sequence of unjaring, copying and jaring tasks.
Yes, it's possible to use it out of eclipse. Try a configuration similar to the following one:
<property name="java.source" value="1.7" />
<property name="java.target" value="1.7" />
<property name="src.dir" location="src" />
<property name="libraries.dir" location="lib" />
<property name="dist.dir" location="out" />
<property name="build.classes.dir" location="${dist.dir}\classes" />
<property name="dist.jar" value="MyJAR.jar" />
<property name="fjepPath" value="${libraries.dir}\fatjar.jar" />
...
<typedef name="fatjar.manifest" classname="net.sf.fjep.anttask.FJManifestType"
classpath="${fjepPath}" loaderref="${fjepPath}" />
<typedef name="fatjar.exclude" classname="net.sf.fjep.anttask.FJExcludeType"
classpath="${fjepPath}" loaderref="${fjepPath}" />
<typedef name="fatjar.jarsource" classname="net.sf.fjep.anttask.FJJarSourceType"
classpath="${fjepPath}" loaderref="${fjepPath}" />
<typedef name="fatjar.filesource" classname="net.sf.fjep.anttask.FJFileSourceType"
classpath="${fjepPath}" loaderref="${fjepPath}" />
<taskdef name="fatjar.build" classname="net.sf.fjep.anttask.FJBuildTask"
classpath="${fjepPath}" loaderref="${fjepPath}" />
...
<target name="buildJar">
<echo>Building JAR</echo>
<fatjar.build output="${dist.dir}\${dist.jar}">
<fatjar.manifest mergemanifests="false" mainclass="com.company.app.Main" />
<fatjar.filesource path="${build.classes.dir}" />
<fatjar.jarsource file="${libraries.dir}\log4j-1.2.17.jar" />
<fatjar.jarsource file="${libraries.dir}\commons-httpclient-2.0.jar" />
...
</fatjar.build>
</target>
精彩评论