Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use an Ant script (Ant is a build tool included with Eclipse) to package the application and all external JAR files into one executable JAR. There may be ways to make this easier (Maven?) but this has worked well for me. This is set up to work with the following project structure (you should adjust the build script as necessary if different):</p> <pre><code>build.xml /src /com /mycompany /myproject [source files] /META-INF MANIFEST.MF /lib jsoup-1.7.2.jar jxl-2.6.10.jar </code></pre> <p>In Eclipse:</p> <ol> <li><p>Add a build.xml file to your project root (this is recognized by Eclipse as an Ant buildfile). Here's one I use - change the "location" values near the top as necessary to point to your source root, etc. Note that the /build and /dist folders are created when the script runs (your compiled JAR will be in the /dist folder).</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- XML file header --&gt; &lt;!-- Define the Ant project name and default task. The project name goes into a variable named "ant.project.name". The default task is the one that will be run automatically by choosing Run As -&gt; Ant Build from the context menu in Eclipse --&gt; &lt;project name="MyProject" default="package"&gt; &lt;!-- Set variables for folder paths that will be used later in the script. The "name" attribute defines the name of the variable (e.g source.dir). The "location" attribute is the relative path of the folder (from the project root). --&gt; &lt;property name="source.dir" location="src"/&gt; &lt;property name="bin.dir" location="bin"/&gt; &lt;property name="lib.dir" location="lib"/&gt; &lt;property name="build.dir" location="build"/&gt; &lt;property name="dist.dir" location="dist"/&gt; &lt;!-- Define the "package" task, which depends on the "clean" task (meaning "clean" will be run automatically when "package" is invoked). --&gt; &lt;target name="package" depends="clean" description="Remake the jarfile from scratch"&gt; &lt;!-- Make a folder with the name in the build.dir variable ("/build") --&gt; &lt;mkdir dir="${build.dir}" /&gt; &lt;!-- Make the "/dist" folder, into which the compiled JAR will go --&gt; &lt;mkdir dir="${dist.dir}" /&gt; &lt;!-- Unzip any JAR files from the "/lib" folder into "/build" --&gt; &lt;unzip dest="${build.dir}"&gt; &lt;fileset dir="${lib.dir}" includes="*.jar" /&gt; &lt;/unzip&gt; &lt;!-- Copy everything from "/bin" to "/build" --&gt; &lt;copy todir="build"&gt; &lt;fileset dir="${bin.dir}" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;!-- Set the location of the JAR manifest in the "manifest.mf" variable. --&gt; &lt;property name="manifest.mf" location="${build.dir}/META-INF/MANIFEST.MF"/&gt; &lt;!-- Create a JAR file from everything in "/build". Set the JAR manifest to the file at the location contained in the "manifest.mf" variable. The completed JAR will be located in the "/dist" folder and will be named "MyProject.jar". --&gt; &lt;jar destfile="${dist.dir}/${ant.project.name}.jar" duplicate="preserve" manifest="${manifest.mf}"&gt; &lt;fileset dir="${build.dir}"/&gt; &lt;/jar&gt; &lt;!-- Delete the "/build" folder --&gt; &lt;delete dir="${build.dir}"/&gt; &lt;/target&gt; &lt;!-- Define the "clean" task, which deletes any old "/build" and "/dist" folders --&gt; &lt;target name="clean" description="Delete the working build and distribution folders"&gt; &lt;!-- Delete the "/build" folder --&gt; &lt;delete dir="${build.dir}"/&gt; &lt;!-- Delete the "/dist" folder --&gt; &lt;delete dir="${dist.dir}"/&gt; &lt;/target&gt; &lt;/project&gt; </code></pre></li> <li><p>If they aren't already, copy the external JAR files into the /lib folder off your project root.</p></li> <li><p>In your /src folder, add a folder titled META-INF. Into this folder, place a file named MANIFEST.MF that contains the following:</p> <pre><code> Manifest-Version: 1.0 Main-Class: [the canonical name of the class you want to launch, e.g. com.mycompany.myproject.MyApp] </code></pre></li> <li><p>In Eclipse, right-click the build.xml file and select Run As -> Ant Build.</p></li> </ol> <p>This will package everything up into one executable JAR file without the hassle of external classpath dependencies.</p> <p>You still may want to use a batch file (or file system shortcut) to launch the JAR if you need to adjust JVM values such as min/max heap size.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload