This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes assignment JAR problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "assignment JAR problem" Watch "assignment JAR problem" New topic
Author

assignment JAR problem

Manuel Comnenus
Ranch Hand

Joined: Apr 26, 2006
Posts: 86
Has anyone else experienced a problem with the assignment JAR? I get the message "Failure to load Main-Class manifest..." Was there anything that you could do to fix the problem besides wait for a response from Sun?
Thanks.
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Manuel Comnenus:
Has anyone else experienced a problem with the assignment JAR? I get the message "Failure to load Main-Class manifest..." Was there anything that you could do to fix the problem besides wait for a response from Sun?
Thanks.


Do you have a file called MANIFEST.MF in the META-INF directory of the jar file. If not you need to create this file and have a line in it as follows:

Main-Class: suncertify.MyPackage.MyMainMethodClass

Without this line the jar is not an executable jar and you will see the error you have specified. If you have this line in then the problem could be that on some windows platforms there must be a blank line at the end of the file (ie hit enter after typing in this line) or it wond load properly.

Hope this solves it,
Mark


SCJP<br />SCJD
Manuel Comnenus
Ranch Hand

Joined: Apr 26, 2006
Posts: 86
Hi Mark,

Thanks for your help. The JAR was downloaded from Sun, rather than being something that I created. Your response helped me figure out the problem. I viewed the JAR contents and noticed that the manifest was indeed in the JAR. So, I used the JAR extraction tool. The problem was based on a bad assumption by me. The JAR is, on my pc, listed as an executable JAR. So, I had expected that I should be able to execute it and that it would programatically unzip itself.
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Manuel Comnenus:
Hi Mark,

Thanks for your help. The JAR was downloaded from Sun, rather than being something that I created. Your response helped me figure out the problem. I viewed the JAR contents and noticed that the manifest was indeed in the JAR. So, I used the JAR extraction tool. The problem was based on a bad assumption by me. The JAR is, on my pc, listed as an executable JAR. So, I had expected that I should be able to execute it and that it would programatically unzip itself.



Super!
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Mark, while making the runme.jar, must I use the Ant approach? If so, in writing the jar target, how to make sure that it will be a runnable jar file?Thanks.


SCJP 1.4 SCJD
Petr Hejl
Ranch Hand

Joined: Feb 26, 2006
Posts: 68
Of course you don't have to use ant. You can just use jar command with m option. If you want to use ant the jar task can contain manifest element - so you can configure manifest content.
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Zhixiong Pan:
Mark, while making the runme.jar, must I use the Ant approach? If so, in writing the jar target, how to make sure that it will be a runnable jar file?Thanks.


As per the above post you don't have to use ant. However if you have a build script anyway the ant task to create the executable jar is as follows:



Mark
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi Mark,
One more problem. The runme.jar which generated by ant can't run when I double click it.
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Zhixiong Pan:
Hi Mark,
One more problem. The runme.jar which generated by ant can't run when I double click it.


Not sure about this one, firstly make sure that you can execute the jar from the command line.

If so another possibility I can think of off the top of my head is that that windows is using a different version of the jre than the one you used from the command line to try to execute the program by default.

Try Tools-> Folder Options -> File Types -> JAR and make sure that windows is using the latest version of the java command (in the bin dir where you installed java 5 / 6) to run the program.

Mark.
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Mark, that problem might come from the package structure. Initially, my suncertify.property and db file lie in the same root as the folder of suncertify, while now they share the root with the folder of code which is the superior folder of suncertify. See my file as following
Should this be changed to . Similarly do change db file load path.Right?
Regards.
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Undo my previous post firstly, cause that's not the crux or the matter.
I can run that jar file in command window. Hope this checking can help Mark go further on my question. Thank you.
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Zhixiong Pan:
Undo my previous post firstly, cause that's not the crux or the matter.
I can run that jar file in command window. Hope this checking can help Mark go further on my question. Thank you.


Have you installed a new version of java recently in order to complete the problem.

As per previous post open up a windows explorer window.


Click on Tools -> Folder Options in top menu menu.

Now click on File Types tab.

Scroll down to JAR file type.

Click on the Advanced button.

In the "action" textarea select open and press the edit button.

Under "application used to perform action" textfield verify that this points to the correct version of java and not an older version of the jre. If this is the case then change this to the correct path.

Should look something like the following if you are using java 5:

"C:\\Java\jre1.5.0_10\bin\javaw.exe" -jar "%1" %*

it should NOT be something like

C:\WINNT\system32\javaw.exe" -jar "%1" %*

Hope this helps.

Mark.
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi Mark,
While double clicking runme.jar, means run the application with no parameter. And the command form without parameter is to launch network client. Consequently, double clicking runme.jar will not work since network client can not go without server started.
BTW, the following ant target is abstracted from one of your posts:

Why take action of excluding suncertify.properties without which application will not work at all.
Regards.
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Zhixiong Pan:

Why take action of excluding suncertify.properties without which application will not work at all.
Regards.



Because my instructions stated that the file should be stored in the current working directory, this is not the same as storing it in the jar file. Bear in mind the user is not necessarily running the application from the same directory that the jar file is in.

If the file does not exist in the current working directory when the application is executed a new one is created from the properties that the user specified, if one exists in the current working directory then the properties from this file are used to lanch the application (after giving the user the opporunity to edit them).

I am not sure if you can even change a file that is contained in a jar file without first extracting the files from the jar, editing it and then re-jaring the files. (open to correction on this).

Mark
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Zhixiong Pan:
[QB]Hi Mark,
While double clicking runme.jar, means run the application with no parameter. And the command form without parameter is to launch network client. Consequently, double clicking runme.jar will not work since network client can not go without server started.QB]


You would need to create a shorcut for each mode to get around this problem.
For alone mode you would create a shortcut called alone pointing to your jar file and then edit the target in shortcut properties to include the parameter.

ie change like this.

"D:\submission\runme.jar" to "D:\submission\runme.jar alone" or "D:\submission\runme.jar server" for server mode.

As you know default shortcut will do for for network mode.

Of course all this this is not nescessary for the project but if you are doing alot of testing then it is useful to be able to start the app in each mode quickly.

Mark.
Roy Pozarelli
Ranch Hand

Joined: Oct 17, 2009
Posts: 39
I'm getting something that I don't really understand. I'm using the command line of:

jar cmfv MANIFEST.MF runme.jar -C classes *

to build the jar file, where MANIFEST.MF is

Manifest-Version: 1.0
Created-By: 1.4.0_01 (Sun Microsystems Inc.)
Class-Path: ./classes
Main-Class: suncertify.gui.launcher.ApplicationLauncher

Now I have a .classpath in the directory where I'm building the jar file from where (I've used eclipse to do the project in) the contents are:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="code"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="classes"/>
</classpath>

Since I wanted to build a "clean" runme.jar file I removed the .classpath, .apt_generated and other files from the directory structure so that they would not be in the runme.jar file. However I discovered that when the .classpath file is not in the runme.jar then when I invoke ">runme.jar alone" (or any other command-line option) it can't find the entry point. Now I thought that the mainfest file took care of that so I'm confused. Also am I being redundant with the -C classes and the manifest entry? Any help would be appreciated.
BTW I'm not using ant.


OCP Java SE 6 Programmer,
OCM Java SE 6 Developer
OCE Web Components
OCE JPA 6
OCE EJB 6
MySQL Certified Administrator & Developer,
OMG Certified UML Prof. Fund., Int., Adv.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Howdy, Roy!

Champ, this thread is sort of old... how about opening a brand new thread, in order to show us your problem? Please avoid waking up such old threads.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roy Pozarelli
Ranch Hand

Joined: Oct 17, 2009
Posts: 39
Sorry, just trying to keep related things together. Could you Roberto, however, give me some insight?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: assignment JAR problem
 
Similar Threads
executable jar
Lost the distribution jar
upload assignement
RMI --about dynamic download
Problem in opening the assignment. Help please!!!