invalid jar - CLDC and MIDP

Invalid jar - That's all the message I get on various phones (Nokia, SE, Samsung). What's important is the fact that I create the jar manually - using JarOutputStream. How can I find out what's wrong? 

The problem is solved. The solution was to use Manifest class instead of creating manifest file manually. 

Here is very useful hint, pay attention to quirks especially.


Creating JAR files fails (?) in SUN1Studio4 [HELP!]

I must be doing something dumb.. surely this has to be as easy as the docs make it look.
rt-clik and do NEW/JAR Packager/JAT Recipe
Folow the instructions, give it a name [NEXT] then drop down the folders to add the thing to JAR up (TableTest in this case) .. adding the object, not the dir but doing it by adding the whole dir gives the same results. Then Manifest GENERATE and FINISH.
Ooops.. it can't find the :
Failed to load Main-Class manifest attribute from
Now I know I've been using Windows for a while and only been on Linux for a year or so but shouldn't this then RUN after you compiile the JAR and then choose EXECUTE ? (Thought that was the general idea of an IDE)
I've looked through the postings here for a few pages and found nothing that solves this.
Are you sposed to keep the filenames all the same? add blank lines to the Manifest data in the window? Stand on one leg and scratch your backside anticlockwise while clicking finish?
Or am I missing something fundamental cos I new to the Java paradigm and it's late? ;o) I RTFM'd an allsorts.
Project is a New/JFrame and runs fine when you hit F6.
Help pls!
cheers all 
Fixed it (I think)
Was doing something moderately dumb.. expecting the I of IDE to mean it... Would be nice if the docs said 'GENERATE does not really generate a working manifest'
Unless I'm still missing something that DOES make GENERATE do what you'd think it would...
(constructive) Hints appreciated if anyone has any
BAH.. that's ok for an app, but not an applet.
Applet complains it can't find method main, wont load in browser but always runs from F6 again...
If the IDE knows how to run it, I don't get why it can't prepare the jar with some HTML tag suggestions for running elsewhere sigh
I have a problem when creating a jar file in Sun One as well. I follow the wizard and create the jar file. When I click on compile it claims to compile the jar file but the jar file is in fact empty except for the manifest file. Sometimes it creates the jar file correctly and some times it just emptys the jar.
I have a war file which contains these jar files and the applets then give class not found error because the jars are empty.
Does anyone know how or why Sun One is doing this to my jar files?
I am also having major hassle trying to create a working .jar file in sun ONE ...
i've followed the tutorials word for word but it still wont work :(
first it was saying it couldn't find the main-class ...
so i solved that now its telling the manifest format is incorrect :|
and no one else on the planet seems to have the answer haha
if anyone figures this out or has any info regarding this could you post it here please :) TIA

Versioning JarFiles In Manifest Automatically

Is there any way to update the Implementation-Version string in a manifest file automatically when a jar file is built? We have a number of different JarFiles we build that make up our system and we need to introduce the concept of jar versioning into the system. We'd like to be able to have the versioning done automatically if it is at all possible. If it's not, I guess a manual update of all the Implementation-Version strings is the best we'll be able to do?
Also, since I'm new to this thing, is there anyway of extracting that version string from the manifest file for display in the system?
Sorry for the basic questions, but I've never really played with Manifests before.
Thanks for any help you may be able to provide.
for automating the manifest versioning you should look into a build tool such as ant. In particular the jar and manifest tasks should be helpful.
As for getting the version string you can's a whole bunch of other infomation you can get in there so check the javadoc.

Giving a tag

We are building jar files for our client.
Can we give a tag in the jar file which will give us our Release version.
Something like Rel4 Patch1
I won't like to touch the code for this.
We use "ant" if this helps.
In all cases for all sections, attributes which are not understood are ignored.
So just make one up and add it. 
Just a small confusion.
I am not a java programmer.
I am in the Build and Release team.
Please can give a clearer indication. It bounced over my head. 
Yes you can, you can make up any attribute name and use it in MANIFEST.MF of your jar-file ('though it would be smart to avoid using an attribute that might be used in the future, prefix your company domain or something). 
It will be very kind of you if you can give an example. 
I've assumed that if you're on the build and release team that you knew how to handle MANIFEST.MF and attributes...
Each jar file contains (should contain) a MANIFEST.MF file that describes the content (and contains signatures and other stuff). There you can add your own attributes as you wish, as long as you don't use existing names. See for details (there's also a standard attribute "Implementation-Version" that might be interesting here).
And read for more details. 
I'll get back to you after reading and implementation. 
I have implemented it in a crude way.
Later will refine it more.
One problem, to see my tag i have to open the manifest file.
Can i see it without opening it.
Any command or tweak.
How on earth would you try to see the contents of a file without opening(i.e. reading) it? 
May be there is an option in "java" or "jar" command by which we can see it.
Or you gurus can give me an option. :-) 
I don't know of such a command, to be honest. I always just open the JAR with a compression application (such as 7zip) and then browse the META-INF dir to see the manifest.
Anyway, it's not such a difficult task to write a simple command line java tool to view the contents of a manifest file, I guess. 
Hey gurus,
Anybody upto the task.

Packaging third jars

Hi All
I was wondering if I could package third party jar files into the jar file generated by my application. The aim is to have one large jar file which contains other third party jar files too. Any pointers in this regard would be great. Also if this is possible how do I specify those jars in the classpath?
Technically you simply unzip the content and add it to your jar. There are several possible problems 'though:
* Legal: Make sure that each License involved actually allows you to do that
* META-INF: The other jar might have some information in it's META-INF and/or MANIFEST.MF, you'll have to figure out how to fix this
* Duplicate classes: if for some reason the original third party jar file and your mega-jar find themselves on the same classpath you'll have serious fun (for very un-fun definitions of "fun").
That beeing said there is a tool names jarjar ( which should help you with the last part. I've just seen (when googling for jarjar), that there is another similar tool named one-jar ( which might be usefull as well. I'd suggest you try both and use what's better for you. 
Or you could just do the normal, standard, thing where you distribute the three jars separately and manage the classpath in the normal way. Did you reject this option for some reason, or did you just not think of it?

How to export a jar from the project

Hello,everyone,I'm a newbie here.
I am working on a java project which uses a lot of external jar files. Meanwhile, I developed a class in this project which replies on these jar files. After I finished this project, I would like to export my custom class with all the reference libraries as a single jar so that I can re-use it in other project.
However, how can I do that?
P.S. I'm using Eclipse as my IDE. 
in eclipse, after successfully compiled all the files then right click on the project and select export option, then u can get the export jar option there. Through using this you can get the jar file 
Actually, I did successfully export the jar file from that project. However, when I use this jar file in another project, the main java program wouldn't compile and it complains that some class is not defined. The fact is, I did include those required libraries in the jar file.
Thanks again for your help. 
Jars inside jars really don't work, so you'll need to keep separate jars and keep track of their dependencies. 
So, do you mean that if my project contains jar, I cannot export my project as a single jar?
If yes, what would you recommend to come across this issue or any suggestions on making it much more simple for the sake of further use in other project?
So, do you mean that if my project contains jar, I cannot export my project as a single jar?Correct.
If yes, what would you recommend to come across this issue or any suggestions on making it much more simple for the sake of further use in other project?Put a Class-path in the manifest of your main jar and ship all the other jars accordingly. See the Javadoc for these items. 
Thanks for your reply,EJP.
Can I make a manifest contains all the jar files? Thus, the main program can locate the jar files. I read the article at
Is it possible?
No, manifests are text files, they can't contain other files. But you can make a manifest whose Class-path: entry lists all the JAR files, which is what I was talking about. Fairly clearly, I would have thought. 
You can also use or similar utilities if you really want only on jar. 
That sounds very complicated. Genarally you can "explode" all the required jars into a directory tree and jar them up again. 
Thanks you guys for the swift replies!
malcolmmc, I think your solution is simple and can solve my problem.
Thanks again. 
Swift wrote:
Thanks you guys for the swift replies!
malcolmmc, I think your solution is simple and can solve my problem.
Thanks again.If you go about exploding the jars and packaging everything as a single jar, be sure to check the licenses of the libraries you are going to explode to be sure it is allowed. For most open source stuff it won't be a problem, but be careful with things like JDBC drivers and such that have a more commercial appliance bound to them. 
Do you mean that their license agreement doesn't allow extracting the jar? Sorry for my naive question.
He means that they might. It's up to you to read the agreements, we can't see them from here.
You also need to consider that you will lose all the information in common files such as META-INF/MANIFEST.MF, which the software in that JAR may rely on in various ways.
In other words you are creating a nightmare. Don't.