java execs

Is there a way to bind all the classes built for an application into one executable?
Currently I have to have all the classes in the working/running directory.
Who is Participating?
for_yanConnect With a Mentor Commented:
Yes, it is true, you should not jar the thord-party jars together:

jar cmf MANIFEST.MF app.jar *.class  top_package1 top_package2

you need to mention the put third party jars inMANIFEST and then put them  in the same folder as app.jar

and then you can  run it

java -jar app.jar

I tried it condensing there together thinking thatmaybe newer java works with it,
and it worked for me, but that happened because actuallt another copy of jar was present in the same folder
CEHJConnect With a Mentor Commented:
You could make a 'one jar' installation. Export in Eclipse will do that for you
for_yanConnect With a Mentor Commented:
You can use either Eclipse or Netbeans - they both have facilty t create executable .jar
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

for_yanConnect With a Mentor Commented:
this is how you craete Exceutabl Jar in Eclipse
for_yanConnect With a Mentor Commented:
this is even simpler to do in Netbeans:
see here descriprtion:

right-click your project,
"set main project",
select your project,
"PROJECTNAME Properties",
set your main class,
"Add JAR/Folder",
select your wanted libs,
do a CLEAN build,
enter the build-path,
enter /dist and be amazed --> DONE!
The last i looked, Netbeans can't do a One Jar export
for_yanConnect With a Mentor Commented:
This is pretty simple explanation of dio-it-yourself method
if you want to be independent of any IDE indpendent of any IDE,:

create MANIFEST.MF file with this content:

Class-path: third-party.jar blort.jar foo.jar

then run in your top-level class folder

jar cmf MANIFEST.MF app.jar *.class  top_package1 top_package2 ... third-party.jar blort.jar foo.jar ...

it will put  your classes from the default package and then process folders  top_package1 top_package2 recursively and put MANIFEST.MF into meta-inf folder (it will create meta-inf folder within the jar  itself)

Then, you can run AppMain like this:

java -jar app.jar
jar cmf MANIFEST.MF app.jar *.class  top_package1 top_package2 ... third-party.jar blort.jar foo.jar ...

Open in new window

That won't work. You can't nest jars
Not quite sure why you accepted that answer. The instructions given, while correct in themselves, don't fulfill your requirement
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.