1

I am creating an executable jar file for my program in java. The program uses jtds.1.2.jar and javacsv-2.0.jar.

Is it possible to include the external jars when I create my executable jar file??

Please help. Thank you.

1
  • Also consider Java Web Start for the deployment. No need (and not recommended) to combine the Jars, just add a reference to each in the launch file. Commented May 30, 2012 at 3:19

4 Answers 4

1

Try this, this is the way to create a jar or runnable jar in eclipse, all your external libraries in the project will be included

File -> Export-> Java ->Runnbale JAR file

Launch configuration : your Class containing the public static void main(String[] args)

Export destination : Target place

Library Handling:

Package required libraries into generated JAR

FINISH
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much!!! In order to run the jar file on any other machine which does not have eclipse what components do we need installed? just jdk and jre?
1

Yes it is possible.

You may use eclipse export jar function doing this

Comments

0

Sure it's possible! Just add the classes of the Jars to your Jar!

You can either do this by hand (unsuggested), or any build tools like Ant ( target) and Maven (search for shading plugin) can do that for you.

If you don't want to bother creating any scripts, just use the IDE to do it for you (newer Eclipse versions have a checkbox for including libraries automatically, for older ones just install a plugin that does the job for you automatically, like the FatJar plugin).

2 Comments

Out of curiosity, why is it a bad idea to do add JARs by hand?
Because you have to do it everytime when you create a new version of your software. If it can be done automatically, it should be done that way.
0

It's possible to create a folder structure like this

main directory:
   your_app.jar
        subdirectory:
           other jar files

Then add the dependencies to your jarfile's manifest and "zip" the whole thing together, to move it to the computer where you want it to be. Netbeans, for example, supports this kind of deployment.

For a more general / "foolproof" solution, you will have to create a setup program.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.