Eclipse Export Jar from command line

Hey guys, I’d like to be able to export a runnable jar from the command line rather than having to go through File->Export->Runnable Jar File->…->Finish. Can I do this with eclipse somehow?
Otherwise, is there a way to get the build script from my project and use ant to build it from the command line?

Thanks,
Roland

Hi

Why not writing your own Ant script from scratch? This is what I do and it has worked very well. I create a “runnable” JAR and I wrap it into a self-contained native application bundle :slight_smile:

From eclipse, go to file -> export -> ant -> ant build script. Voila.

However, that introduces dependencies on eclipse, so building your own might be the way to go.

What kind of dependencies do you have? Just creating an ant build script from scratch would take less time than waiting on replies in a forum, imho…

Thanks for the reply :slight_smile:
What do you mean by introducing dependencies?

I have a semi-complicated setup. My game engine, rendering & network code are split into separate projects, plus separate projects for my game client, server and updater. They require some external libraries ( rhino js, poly2tri, apache commons etc) the client/renderer requires LWJGL.

I need to build 3 jars
-client
-server
-updater

and it would be great if I could just run ant files for all three (I want to make this an automated process I can run from a build server)

Thanks again,
roland

Maybe this is the way to go. Just feels like a complicated task to do it from scratch and make it work with my setup (above) However I’m willing to give it a shot :slight_smile: Do you have any more information / good links on this?
Thanks

Try exporting the ant build script and looking at it to see what I mean. It includes eclipse stuff that you probably don’t need, but eclipse adds for whatever reason.

That doesn’t sound that complicated. Maybe try exporting the ant build file from eclipse just to see what an ant build script looks like, then create your own based on the one exported from eclipse, but without the eclipse dependencies?

You can look at this section of my latest article, I suggest some tools but it would be a bit harder to use in your case as you use a library with no equivalent of “automated native library loading”, you’ll have to manage the Java library path by yourself:

I use lots of third party libraries and it works for me, it should work for you too. My build is entirely automated, from the compiling to the upload of the bundles (SFTP).

Thanks both of you for the replies. :slight_smile: I will build ant files from scratch once I get the exported one working.

I exported the ant buildfiles and it created a build.xml for each of my projects. I ran “ant” inside my client directory and it said build successful (with a bunch of warnings) but I can’t find a jar file that was built / exported. Is this right? Exporting the jar using eclipse normally takes more than 2 seconds.


C:\Storm>ant

Buildfile: C:\Storm\build.xml

build-subprojects:

init:

... (repeats of below for each included project)

build-project:
     [echo] Storm: C:\[...]\build.xml
    [javac] C:\Storm\build.xml:222: warning: 'includeant
runtime' was not set, defaulting to build.sysclasspath=last; set to false for re
peatable builds

build:

BUILD SUCCESSFUL
Total time: 2 seconds

I am very interested in using JNDT. I am using Launch4j at the moment but it’s really only a good windows solution. I’m going to look into this further when I have time to test mac and linux further. :slight_smile:

Well, look in the ant build file to see where it’s putting the jars!

You can go on using Launch4j under Windows until I implement MSI support. Please note that JNDT is under GPL. If you have no plan to put your own code under GPL, you’ll have to use another tool (for example PackR). I remind it because I don’t want you to waste your precious time with a tool that you can’t use.

Well turns out my version of eclipse ant export doesn’t even have the right commands to build the jar file in there. I guess I’m just going to end up doing it from scratch following http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html

Oh, thanks for letting me know. Unfortunately I can’t put my code under GPL. :frowning:
Roland

Update: It’s a lot easier than I thought to create a custom build script following that tutorial (http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html), rather than using eclipse to do it. Thanks guys.
I made a single build.xml that builds a test project, including bundling libraries and including source projects from other files rather than having to create a separate build.xml for each project.

Thanks again :slight_smile:


<project name="TestAntSimple" basedir="." default="main">

	<property environment="env"/>
	<property name="debuglevel" value="source,lines,vars"/>
	<property name="target" value="1.6"/>
	<property name="source" value="1.6"/>
	
	<property name="src.dir"     value="src"/>
	<property name="src2.dir"     value="../TestAntSimpleChildProject/src"/>
	
    <property name="build.dir"   value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>
    <property name="main-class"  value="testantsimple.Main"/>
	<property name="jar.name"    value="testantsimple.jar"/>
	<property name="lib.dir"     value="../Storm Libraries/"/>
	<property name="lib.includes"     value="**/*.jar"/>

    <path id="classpath">
        <fileset dir="${lib.dir}" includes="${lib.includes}"/>
    </path>
	
	<target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac includeantruntime="false" destdir="${classes.dir}" classpathref="classpath">
			<src path="${src.dir}"/>
			<src path="${src2.dir}"/>
		</javac>
    </target>

    <target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${jar.name}" basedir="${classes.dir}">
			<zipgroupfileset dir="${lib.dir}" includes="${lib.includes}" excludes=""/>
			
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java jar="${jar.dir}/${jar.name}" fork="true"/>
    </target>

    <target name="clean-build" depends="clean,jar"/>

    <target name="main" depends="clean,run"/>
	
</project>