0

I have a Java test app. The code sample for the import section follows. I created a quick/short bash script to build the app/run the app. Everything works. The Java test runs.

I'm trying to figure out how to quickly/easily "package" the Java app (and all the associated files) to run the Java test on another Linux box.

Pointers to solutions would be appreciated.

Test code:

  import java.sql.*; 
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.util.Date;

  import org.json.simple.*; // json package, download at http://code.google.com/p/json-simple/ 

  import java.net.URLDecoder;
  import java.net.URLEncoder;
  import java.lang.String.*;

  public class ms1 {
    private Connection conn = null;
    private Statement stmt = null;

 .
 .
 .

Is it as simple as doing a tar? Is this a package thing? Trying to get my head around how this works for small projects in Java.

update::

The test is all from the cmdline. There's no using of an IDE/Eclipse.

I run the test using the run/cmdline:

javac -classpath '/usr/share/java/json_simple-1.1.jar:/opt/selenium/selenium-server-standalone.jar:/apps/parseapp2/' ms1.java 'foo'
tom smith
  • 1,035
  • 7
  • 23
  • 39
  • How do you expect your program to be run and by whom? – Thorbjørn Ravn Andersen Mar 09 '12 at 04:00
  • If you have multiple libraries (jar files) for your classpath, the simplest thing will be to export your application as jar, then create an executatble shell script with the command as your test command (with -classpath defining the extra libraries) and pack all including the extra libraries together in to a tar/zip file. The end user will have to extract it and run the shell script – prajeesh kumar Mar 09 '12 at 04:55

5 Answers5

0

If you are using Eclipse, go to File > Export > Java > Executable Jar. Then type in the name and select the class that contains the main method.

Stas Jaro
  • 4,747
  • 5
  • 31
  • 53
0

A tar-like package format for Java projects is jar (surprise!). :)

If you downloaded a JDK, jar is included, on linux together probably with a man jar, with a HTML-doc: file:///$JAVA_HOME/docs/technotes/guides/jar/index.html.

Your users need a JVM-runtime, your classes in their hierarchy, which reflects the package structure, and external jars - in your case the JSON package. You usually provide your own classes, but might provide (if the license allows it) foreign jars as well.

user unknown
  • 35,537
  • 11
  • 75
  • 121
0

File > Export > Java > Runnable Jar > Extract.

Copy the jar and the jar_lib folder to the other linux box

Run java yourjarfile.jar -lib yourjarfile_lib/

Siddharth
  • 9,349
  • 16
  • 86
  • 148
0

If these tasks are iterative, I will probably create an ant build file with a few target like compile, jar and scp. It should be easy to create ant build file in eclipse. You can check out the manual for ant tasks and steps to create ant build file in eclipse. Once it is created, it is as easy to run like ant compile scp (example) in the console.

Jasonw
  • 5,054
  • 7
  • 43
  • 48
0

First of all you need to learn how to use Class-Path inside the MANIFEST.MF file to enable "java -jar parseapp.jar" (instead of having to specify the full path). Place your dependent jars in a "lib" folder next to your main jar, so you can have relative paths in the Class-Path.

When that is working you essentially have three choices:

  • create a zip-file containg your jar and supportive jars. The recipient must then unpack the zip, and invoke the main jar (e.g. by clicking)
  • use one-jar to wrap it all up in a single jar file which can then be distributed, and the user invoke (e.g. by clicking). There is magic in this, which may or may not be a showstopper.
  • Use Java WebStart to have your application on a web server so the user can just click a link and have the program started. This is primarily intended for GUI programs but is very powerful and simple to maintain.
Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347