Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jiddick ExRex

macrumors 65816
Original poster
May 14, 2006
1,469
0
Roskilde, DK
And by noob, I mean myself.

I have this project in Eclipse that is depending on the framework of another project. File structure is:
~Documents/Eclipse Workspace/
________
MakiSearch/ (main project, contains a src, bin and images folder).
piccolo/ (depending framework).

I need to make the main project into an executable .jar file that can be run on other computers.
Basically I have tried Eclipse's way of making jars, and also through the terminal by: jar cf MakiSearch.jar * in the MakiSearch folder. I do get a .jar out if but it cannot be executed, gives me an error:
"5/22/08 2:53:16 PM [0x0-0x16c16c].com.apple.JarLauncher[35243] Failed to load Main-Class manifest attribute from ~/Documents/Eclipse workspace/MakiSearch/MakiSearch.jar "

Do I need to somehow specify the .class file which contains the main method? How?
Do I need to jar both the main project and the depending project?
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
And by noob, I mean myself.

I have this project in Eclipse that is depending on the framework of another project. File structure is:
~Documents/Eclipse Workspace/
________
MakiSearch/ (main project, contains a src, bin and images folder).
piccolo/ (depending framework).

I need to make the main project into an executable .jar file that can be run on other computers.
Basically I have tried Eclipse's way of making jars, and also through the terminal by: jar cf MakiSearch.jar * in the MakiSearch folder. I do get a .jar out if but it cannot be executed, gives me an error:
"5/22/08 2:53:16 PM [0x0-0x16c16c].com.apple.JarLauncher[35243] Failed to load Main-Class manifest attribute from ~/Documents/Eclipse workspace/MakiSearch/MakiSearch.jar "

Do I need to somehow specify the .class file which contains the main method? How?
Do I need to jar both the main project and the depending project?
Yes, and yes.

Specifying the main class requires creating a small text file with this information, as well as an empty line at the end for it to be parsed properly. To add this to the JAR file you add the m option, and the name of the text file BEFORE the name of the JAR file - for example: jar cmf manifest.txt MakiSearch.jar *

It's easiest for your users if you either JAR the dependency inside the main JAR or include it in a second library JAR distributed with your application.

To specify the main class you need to fully qualify its name - this also won't work unless you're in the directory outside all the package directories. For example, if your project structure looks like this:
~/Documents/Projects/Test (main project folder)
~/Documents/Projects/Test/build/manifest.txt (file with main class info)
~/Documents/Projects/Test/build/mypackage (folder where all the .class files live)
You would cd to the build folder (NOT the mypackage folder), then use this command to make the JAR file:
jar cmf manifest.txt Test.jar mypackage/*
 

foidulus

macrumors 6502a
Jan 15, 2007
904
1
You can create a Manifest file and run the jar command

which works alright, but if you are going to be doing this task a number of times, I would investigate ant, more specifically ant jar tasks. Ant is an automated way to build your project and works great with eclipse. It will require a bit of an investment up front, but it will be well worth it in my opinion. Plus, it saves you from having to learn the syntax of manifest files.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.