473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems creatng executible jar files

This is quite frustrating! In the documents, and in the newsgroups, I see
simple instructions like the following:

===============================================
==========Beginning of Ray's example=================
===============================================
Suppose you want to run class com.xyz.Main. Then create a manifest file
like this:

======== main.mf starts on the next line ====
Main-Class: com.xyz.Main

======== end of main.mf =====================

(Where the lines with === above are not actually in the file.)

Then create your jar file:

$ jar cvfm xyz.jar main.mf com/xyz/*.class

===============================================
=========end of Ray's example=======================
===============================================

With such simple instructions, it is quite frustrating to see the
recommended procedure failing without any information as to what caused the
problem.

I have appended what I see in the command console after following Ray's
instructions, changing only file and class names to match the files I'm
using in my test. No error ever appears in the comsole or when compiling
the code. However, when I try to run it, I get an error message dialog box
saying that the main class could not be found.

I do not know if it makes a difference, but HotSpotImageTest is derived from
JApplet and has function main. It runs fine within JBuilder, and I have
compiled it without problems from the command line using only Sun's SDK.
And it runs fine as an applet, but this jar file business is giving me
grief.

If it makes a difference, this application/applet makes considerable use of
Swing.

Once this problem is resolved, I need to be able to make the jar file self
contained, including in it everything that the application needs to run so
that I do not have to worry about the version of the java runtime on the
client machine or whether or not there is support for Swing on it. IS this
possible? If so, how? I do not really want to be installing a new JVM on a
client machine unless I absolutely have no choice in the matter.

Thanks,

Ted

=======contents of manifest.mf==(including a couple empty lines at the end
of the file)====
Main-Class: HotSpotImageTest

===========Partial session record==================
H:\JavaProjects\HotImage\HotImage\classes\hotimage >dir
Volume in drive H is Local Disk
Volume Serial Number is 686B-F4CF

Directory of H:\JavaProjects\HotImage\HotImage\classes\hotimage

06/04/2004 01:06p <DIR> .
06/04/2004 01:06p <DIR> ..
28/03/2002 11:29p 78,727 daynite.gif
28/03/2002 11:18p 7,667 deerani.gif
31/03/2004 04:07p 4,757 HotSpotImageTest.class
06/04/2004 01:06p 103,281 HotSpotImageTest.jar
31/03/2004 04:07p 683
HotSpotImageTest_jLabel1_mouseAdapter.class
31/03/2004 04:07p 935
HotSpotImageTest_jLabel2_mouseAdapter.class
06/04/2004 01:04p 30 manifest.mf
21/06/2003 04:42a 100,096 sunset.jpg
8 File(s) 296,176 bytes
2 Dir(s) 17,338,773,504 bytes free

H:\JavaProjects\HotImage\HotImage\classes\hotimage >HotSpotImageTest
'HotSpotImageTest' is not recognized as an internal or external command,
operable program or batch file.

H:\JavaProjects\HotImage\HotImage\classes\hotimage >HotSpotImageTest.jar

H:\JavaProjects\HotImage\HotImage\classes\hotimage >jar cvfm
HotSpotImageTest.jar manifest.
mf *.class *.jpg
added manifest
adding: HotSpotImageTest.class(in = 4757) (out= 2304)(deflated 51%)
adding: HotSpotImageTest_jLabel1_mouseAdapter.class(in = 683) (out=
358)(deflated 47%)
adding: HotSpotImageTest_jLabel2_mouseAdapter.class(in = 935) (out=
413)(deflated 55%)
adding: sunset.jpg(in = 100096) (out= 99228)(deflated 0%)

H:\JavaProjects\HotImage\HotImage\classes\hotimage >HotSpotImageTest.jar

H:\JavaProjects\HotImage\HotImage\classes\hotimage >
Jul 17 '05 #1
3 2466
Ted Byers wrote:

=======contents of manifest.mf==(including a couple empty lines at the end
of the file)====
Main-Class: HotSpotImageTest

===========Partial session record==================
H:\JavaProjects\HotImage\HotImage\classes\hotimage >dir
Volume in drive H is Local Disk
Volume Serial Number is 686B-F4CF

Directory of H:\JavaProjects\HotImage\HotImage\classes\hotimage

06/04/2004 01:06p <DIR> .
06/04/2004 01:06p <DIR> ..
28/03/2002 11:29p 78,727 daynite.gif
28/03/2002 11:18p 7,667 deerani.gif
31/03/2004 04:07p 4,757 HotSpotImageTest.class
06/04/2004 01:06p 103,281 HotSpotImageTest.jar
31/03/2004 04:07p 683
HotSpotImageTest_jLabel1_mouseAdapter.class
31/03/2004 04:07p 935
HotSpotImageTest_jLabel2_mouseAdapter.class
06/04/2004 01:04p 30 manifest.mf
21/06/2003 04:42a 100,096 sunset.jpg
8 File(s) 296,176 bytes
2 Dir(s) 17,338,773,504 bytes free

H:\JavaProjects\HotImage\HotImage\classes\hotimage >HotSpotImageTest
'HotSpotImageTest' is not recognized as an internal or external command,
operable program or batch file.

H:\JavaProjects\HotImage\HotImage\classes\hotimage >HotSpotImageTest.jar

H:\JavaProjects\HotImage\HotImage\classes\hotimage >jar cvfm
HotSpotImageTest.jar manifest.
mf *.class *.jpg
added manifest
adding: HotSpotImageTest.class(in = 4757) (out= 2304)(deflated 51%)
adding: HotSpotImageTest_jLabel1_mouseAdapter.class(in = 683) (out=
358)(deflated 47%)
adding: HotSpotImageTest_jLabel2_mouseAdapter.class(in = 935) (out=
413)(deflated 55%)
adding: sunset.jpg(in = 100096) (out= 99228)(deflated 0%)

H:\JavaProjects\HotImage\HotImage\classes\hotimage >HotSpotImageTest.jar

H:\JavaProjects\HotImage\HotImage\classes\hotimage >


Ted,

It may be that *.jar files are not properly configured on your Windows
machine. (Sometimes other programs, like zip programs, hijack *.jar
extensions for themselves.) Try this:

java -jar HotSpotImageTest.jar

If java is not found, enter the full path to java.exe, e.g.

C:\j2sdk1.4.2_03\bin\java.exe -jar HotSpotImageTest.jar

Now you should at least get some error messages.

Ray
Jul 17 '05 #2

"Raymond DeCampo" <rd******@spam.twcny.spam.rr.spam.com.spam> wrote in
message news:%k***************@twister.nyroc.rr.com...
Ted Byers wrote:


Ted,

It may be that *.jar files are not properly configured on your Windows
machine. (Sometimes other programs, like zip programs, hijack *.jar
extensions for themselves.) Try this:

java -jar HotSpotImageTest.jar

If java is not found, enter the full path to java.exe, e.g.

C:\j2sdk1.4.2_03\bin\java.exe -jar HotSpotImageTest.jar

Now you should at least get some error messages.

Thanks Ray

Yes, now I get an error message. The following one:

H:\JavaProjects\HotImage\HotImage\classes\hotimage >java -jar
HotSpotImageTest.jar
Exception in thread "main" java.lang.NoClassDefFoundError: HotSpotImageTest
(wrong name: hotimage/HotSpotImageTest)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java :502)
at
java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader .java:250)
at java.net.URLClassLoader.access$100(URLClassLoader. java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 99)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 55)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:315)

Here's the contents of my directory:
31/03/2004 04:07p 4,757 HotSpotImageTest.class
06/04/2004 01:06p 103,281 HotSpotImageTest.jar
31/03/2004 04:07p 683
HotSpotImageTest_jLabel1_mouseAdapter.class
31/03/2004 04:07p 935
HotSpotImageTest_jLabel2_mouseAdapter.class
06/04/2004 01:04p 30 manifest.mf
21/06/2003 04:42a 100,096 sunset.jpg

This is in manifest.mf:
Main-Class: HotSpotImageTest
And here are the first few lines of HotSpotImageTest.java:

package hotimage;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import com.borland.jbcl.layout.*;
import javax.swing.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @Ted Byers
* @version 1.0
*/

public class HotSpotImageTest extends JApplet {
....

Have I overlooked something here, or is my installation of the SDK broken?
You DID say "It may be that *.jar files are not properly configured on your
Windows machine. (Sometimes other programs, like zip programs, hijack *.jar
extensions for themselves.)" If this is broken, how do I fix it, and is the
cause of the exception I got when I tried "java -jar HotSpotImageTest.jar"?

Here is another, unrelated question. What is the "package hotimage;" for?
It was added, along with the other first half dozen lines, by JBuilder, and
it isn't the sort of thing I normally think about when working on a little
project. Is it really necessary, or can it be removed without risk?

Thanks,

Ted
Jul 17 '05 #3
Ted Byers wrote:

Yes, now I get an error message. The following one:

H:\JavaProjects\HotImage\HotImage\classes\hotimage >java -jar
HotSpotImageTest.jar
Exception in thread "main" java.lang.NoClassDefFoundError: HotSpotImageTest
(wrong name: hotimage/HotSpotImageTest)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java :502)
at
java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader .java:250)
at java.net.URLClassLoader.access$100(URLClassLoader. java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 99)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 55)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:315)

[snip]

Have I overlooked something here, or is my installation of the SDK broken?
You DID say "It may be that *.jar files are not properly configured on your
Windows machine. (Sometimes other programs, like zip programs, hijack *.jar
extensions for themselves.)" If this is broken, how do I fix it, and is the
cause of the exception I got when I tried "java -jar HotSpotImageTest.jar"?

Here is another, unrelated question. What is the "package hotimage;" for?
It was added, along with the other first half dozen lines, by JBuilder, and
it isn't the sort of thing I normally think about when working on a little
project. Is it really necessary, or can it be removed without risk?


Aha, this is indeed the source of your problem. You could get around it
by getting rid of the package declaration, but you will be better off in
the long run if you keep it and fix your problem.

Here's how to fix the problem. First, in the MANIFEST.MF the Main-Class
attribute must be the fully-qualified name of the class. In this case
the FQN is "hotimage.HotSpotImageTest".

Second, make sure you have the jar file packaged correctly. The
HotSpotImageTest.class file should be in a hotimage directory in the jar
file. Test this by entering in "jar tvf xyz.jar
hotimage/HotSpotImageTest.class". You should see some details about the
file within the jar.

Now you should be good to go, using the command as before.
Now, why use packages and what do they do? Packages provide a name
space for your classes. The Java standard is to use the reverse of your
domain name plus whatever you want for your packages. For example, if
your company owns xyz.com, use com.xyz. This way you will not meet any
other classes from other libraries with the same name as your class.

When the JVM attempts to load a class with a package declaration, it
turns the '.' characters into '/' characters, appends the ".class".
Then each location in the CLASSPATH is treated as the base until one of
the locations contains the class. For example, if the CLASSPATH is
"my/classes;abc.jar" and the JVM tries to load com.xyz.Main, it will
look for "my/classes/com/xyz/Main.class". Failing that, it will look
for "com/xyz/Main.class" within the abc.jar jar file.

(Disclaimer: the above paragraph assumes you are using the default
UrlClassLoader. If you are using a different ClassLoader, different
things will happen.)

Note that when you run the JVM using the -jar option, the jar file is
prepended to the CLASSPATH, the remainder of which comes from the
Class-Path entry in the META-INF/MANIFEST.MF, if it exists.

Finally, there are some other reasons to use packages. When you make an
instance variable or a method with no access specifier (i.e. private,
protected or public), that variable or method has package level access.
That means any other class in the same package can see the variable or
method. This is similar to the C++ "friends" concept.
OK, you asked about associating jar files on Windows. To manage file
associations on Windows, open the Explorer. Go to Tools->Options and
select the File Types tab. (This may be different in the various
flavors of Windows.) You should see a list of file types. Find the JAR
file type. You need to change the default application associated with
JAR files to be javaw and pass the -jar option. (Actually, you may not
need to do this. Since javaw is a true Windows program, it does not
have a console and so it could not emit error messages. So the behavior
you saw before is consistent with that.)

HTH,
Ray

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1962
by: John Caruthers | last post by:
HELP! This problem is driving me crazy. All other web sites that are being served out through this server are working, including sites and virtual directories that are under the Default Web...
15
425
by: Rob Ratcliff | last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray X1. It makes heavy use of templates and namespaces. Up until the link step, the C++ source code compiled flawlessly. But, when...
2
2095
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
21
2905
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
2
1232
by: Jack Fox | last post by:
We are encountering a couple of problems with our ASP.NET / IIS 6.0 applications: In each of 3 production environments we maintain a Windows Server 2003 machine running NTFS as a file server....
2
3249
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
2
2844
by: subsanta | last post by:
My computer has so many problems and ive looked around on the internet and ive managed to fix some of them. I know that i have a few viruses on my computer, but i cant get rid of them, in one case i...
3
2608
by: =?Utf-8?B?VG9kZCBEb2JtZXllcg==?= | last post by:
I am working on developing a program using Visual Studio 2003 but am having problems getting my program to find my GL.h and GLU.h, and I am guessing it will have the same problems trying to link to...
34
5296
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
0
7120
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.