How do you create a single runnable jar that contains all the files it needs to run? This is one of those questions that should be easier to answer. Here’s how to do it in eclipse and NetBeans.

First, eclipse, following the post here:
1. Create a Java class to run your Scala main:

package scala.loader;
import java.util.*;
public class ScalaEntryPoint
{
    public static void main(String[] args) {
    List<string> argList = new ArrayList<string>();
    argList.add("YourScalaObjectWithMain");
    for (String s : args) argList.add(s);
        scala.tools.nsc.MainGenericRunner.main(argList.toArray(new String[0]));
    }
}

Be sure to change YourScalaObjectWithMain to your class. Also, you’ll have to add the Scala tools jar to your projects classpath: Project | Properties | Java Build Path tab | Libraries tab | Add External Jars… button. Then pick the scala.tools.nsc file in your eclipse/plugins folder.

2. Create a Run Configuration to run the Java class. Check that it runs.

3. Then choose File | Export…, then Java | Runnable JAR File, then pick the Java run configuration to export and a destination. Optionally, you can save the ant XML file that does the export. Later, after some edits, you can rejar using

ant -f yourjarXMLfile.xml

If you change your libraries, be sure to repeat the complete Export process to make sure your jar scrips includes the correct jars.


Bookmark and Share

Tags: ,

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>