By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,553 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,553 IT Pros & Developers. It's quick & easy.

Executable jar file problem

P: n/a
Problem:
--------
I'm trying to create an executable jar file. I can do so as long as
I don't use the "package" statement in my source code. Once I put the
package statement in I can't execute the jar file.

Here is the criteria of what I am working with:
-----------------------------------------------
Working directory:
------------------
/home/emartin/testArea

Classpath is set to:
--------------------
export CLASSPATH=$CLASSPATH:.:/usr/java/lib/tools.jar:/usr/java/lib/dt.jar:/usr/java/lib/htmlconver
ter.jar:/home/emartin

Source file name: test.java

Contents of test.java :
--------------------------------
package testArea;

import java.io.*;
import java.net.*;
import java.util.*;

public class test
{
public test (){}

public static void main (String[] args)
{
try
{
System.out.println( "test.main() Hey there!");

}
catch (Exception e)
{
e.printStackTrace();
}
}
}

--------------------------------

Contents of ManifestHeader.txt :
--------------------------------
Main-Class: testArea.test

Build Procedure:
----------------
javac test.java

Builds a test.class file which runs fine as follows:
----------------------------------------------------
java testArea.test

Build an executable jar file using the manifest file as follows:
----------------------------------------------------------------
jar cmf ManifestHeader.txt test.jar test.class

Execute the jar file as follows:
--------------------------------
java -jar test.jar

I get the following error when trying to execute the jar file:
--------------------------------------------------------------
Exception in thread "main" java.lang.NoClassDefFoundError:
testArea/test

It's acting like it can't understand what the CLASSPATH is set to.
I've tried various combinations of compiling and running with
the -classpath arguement to javac and java, respectively.
But nothing seems to work.
Has anyone else had problems with this or am I missing something
very fundamental?

Regards,
--Eric
Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Eric wrote:

Build an executable jar file using the manifest file as follows:
----------------------------------------------------------------
jar cmf ManifestHeader.txt test.jar test.class
I get the following error when trying to execute the jar file:
--------------------------------------------------------------
Exception in thread "main" java.lang.NoClassDefFoundError:
testArea/test

It's acting like it can't understand what the CLASSPATH is set to.
I've tried various combinations of compiling and running with
the -classpath arguement to javac and java, respectively.
But nothing seems to work.
Has anyone else had problems with this or am I missing something
very fundamental?


Eric,

The problem is that the class file should be in a directory dictated by
the package name. In this case, test.class should be in testArea/.
Arrange your file system so you can execute the jar command like so:

jar cmf ManifestHeader.txt test.jar testArea/test.class

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

P: n/a
Raymond DeCampo <rd******@spam.twcny.spam.rr.spam.com.spam> wrote in message news:<JN********************@twister.nyroc.rr.com> ...
Eric wrote:

Build an executable jar file using the manifest file as follows:
----------------------------------------------------------------
jar cmf ManifestHeader.txt test.jar test.class
I get the following error when trying to execute the jar file:
--------------------------------------------------------------
Exception in thread "main" java.lang.NoClassDefFoundError:
testArea/test

It's acting like it can't understand what the CLASSPATH is set to.
I've tried various combinations of compiling and running with
the -classpath arguement to javac and java, respectively.
But nothing seems to work.
Has anyone else had problems with this or am I missing something
very fundamental?


Eric,

The problem is that the class file should be in a directory dictated by
the package name. In this case, test.class should be in testArea/.
Arrange your file system so you can execute the jar command like so:

jar cmf ManifestHeader.txt test.jar testArea/test.class

HTH,
Ray


Ray,
Thanks for taking the time to review my post and giving me some
feedback. It worked beautifully!! I now have an executable jar file.
It also enlighted me to that fundamental piece that I was missing.
Thanks again Ray, it's appreciated.
--Eric
Jul 17 '05 #3

P: n/a
Hi Eric,

Hope you got solutions to your problem.If so please guide me how did
do solve it?I am creating an executable jar file butI don't have an
package in my application.

Working Directory
--------------
D:\Mp3ToRingTone
Main Class is :mp3Player

Contents of Manifest file
---------------------
Manifest-Version: 1.0
Main-Class: mp3player
Created-By: Roopa

<I have left 2 blank lines>

when i run
java mp3player it launch the application without any problem

Command used to Buid the Jar file
---------------
jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class

Execute the Jar
java -jar MyRingRone.jar

I get the following error Exception in thread "main
java.lang.NoClassDefFoundError: MyFileFilter

MyFileFilter is class, which i am using in mp3player.java. And when
unpack the jar file MyFileFilter.class exists. I don't understand wha
is the problem.

Any suggestion or guidence would be highly appriciated.
Thanks in advance
Roopa.




Raymond DeCampo wrote:
*Eric wrote:

Build an executable jar file using the manifest file as follows:
----------------------------------------------------------------
jar cmf ManifestHeader.txt test.jar test.class
I get the following error when trying to execute the jar file:
--------------------------------------------------------------
Exception in thread "main" java.lang.NoClassDefFoundError:
testArea/test

It's acting like it can't understand what the CLASSPATH is set to.
I've tried various combinations of compiling and running with
the -classpath arguement to javac and java, respectively.
But nothing seems to work.
Has anyone else had problems with this or am I missing something
very fundamental?


Eric,

The problem is that the class file should be in a directory dictate
by
the package name. In this case, test.class should be in testArea/.
Arrange your file system so you can execute the jar command like so:

jar cmf ManifestHeader.txt test.jar testArea/test.class

HTH,
Ray

--
XML is the programmer's duct tape.

-
roopa_g
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Jul 17 '05 #4

P: n/a
Hello

Please verify the Classpath. It should include the pwd(Present Working
Directory) representd by ".".

i.e...
CLASSPATH = c:/j2sdk/lib;.;

May be that will help.

roopa_gh <ro*************@mail.codecomments.com> wrote in message news:<4b******************************@news.thenew sgroups.com>...
Hi Eric,

Hope you got solutions to your problem.If so please guide me how did u
do solve it?I am creating an executable jar file butI don't have any
package in my application.

Working Directory
--------------
D:\Mp3ToRingTone
Main Class is :mp3Player

Contents of Manifest file
---------------------
Manifest-Version: 1.0
Main-Class: mp3player
Created-By: Roopa

<I have left 2 blank lines>

when i run
java mp3player it launch the application without any problem

Command used to Buid the Jar file
---------------
jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class

Execute the Jar
java -jar MyRingRone.jar

I get the following error Exception in thread "main"
java.lang.NoClassDefFoundError: MyFileFilter

MyFileFilter is class, which i am using in mp3player.java. And when i
unpack the jar file MyFileFilter.class exists. I don't understand what
is the problem.

Any suggestion or guidence would be highly appriciated.
Thanks in advance
Roopa.




Raymond DeCampo wrote:
*Eric wrote:

Build an executable jar file using the manifest file as follows:
----------------------------------------------------------------
jar cmf ManifestHeader.txt test.jar test.class
I get the following error when trying to execute the jar file:
--------------------------------------------------------------
Exception in thread "main" java.lang.NoClassDefFoundError:
testArea/test

It's acting like it can't understand what the CLASSPATH is set to.
I've tried various combinations of compiling and running with
the -classpath arguement to javac and java, respectively.
But nothing seems to work.
Has anyone else had problems with this or am I missing something
very fundamental?


Eric,

The problem is that the class file should be in a directory dictated
by
the package name. In this case, test.class should be in testArea/.
Arrange your file system so you can execute the jar command like so:

jar cmf ManifestHeader.txt test.jar testArea/test.class

HTH,
Ray

--
XML is the programmer's duct tape. *

Jul 17 '05 #5

P: n/a
roopa_gh wrote:
Hi Eric,

Hope you got solutions to your problem.If so please guide me how did u
do solve it?I am creating an executable jar file butI don't have any
package in my application.

Working Directory
--------------
D:\Mp3ToRingTone
Main Class is :mp3Player

Contents of Manifest file
---------------------
Manifest-Version: 1.0
Main-Class: mp3player
Created-By: Roopa

<I have left 2 blank lines>

when i run
java mp3player it launch the application without any problem

Command used to Buid the Jar file
---------------
jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class

Execute the Jar
java -jar MyRingRone.jar

I get the following error Exception in thread "main"
java.lang.NoClassDefFoundError: MyFileFilter

MyFileFilter is class, which i am using in mp3player.java. And when i
unpack the jar file MyFileFilter.class exists. I don't understand what
is the problem.


Roopa,

Note that a NoClassDefFoundError is different from a
ClassNotFoundException. An ClassNotFoundException usually indicates a
classpath problem. A NoClassDefFoundError indicates a more complex
problem, e.g., a corrupt or incompatible class file.

Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #6

P: n/a
Hi Gridhar,
Thanks for your kind reply. I have cehcked with classpath. still i a
having same problem. But when i run application without jar it work
fine. Any more suggestion?

Thanks in advance,
Roopa.

Please verify the Classpath. It should include the pwd(Present Working
Directory) representd by ".".

i.e...
CLASSPATH = c:/j2sdk/lib;.;

May be that will help.

roopa_gh <ro*************@mail.codecomments.com> wrote in messag
news:<4b******************************@news.thenew sgroups.com>...
Hi Eric,

Hope you got solutions to your problem.If so please guide me how di u do solve it?I am creating an executable jar file butI don't have any
package in my application.

Working Directory
--------------
D:\Mp3ToRingTone
Main Class is :mp3Player

Contents of Manifest file
---------------------
Manifest-Version: 1.0
Main-Class: mp3player
Created-By: Roopa

<I have left 2 blank lines>

when i run
java mp3player it launch the application without any problem

Command used to Buid the Jar file
---------------
jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class

Execute the Jar
java -jar MyRingRone.jar

I get the following error Exception in thread "main"
java.lang.NoClassDefFoundError: MyFileFilter

MyFileFilter is class, which i am using in mp3player.java. And whe i unpack the jar file MyFileFilter.class exists. I don't understan what is the problem.

Any suggestion or guidence would be highly appriciated.
Thanks in advance
Roopa.




Raymond DeCampo wrote: [/B

-
roopa_g
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Jul 17 '05 #7

P: n/a
Hi Ray,

Thanks for your kind response.
You said A NoClassDefFoundError indicates a more complex
problem, e.g., a corrupt or incompatible class file.

But my application works fine without jar. Is there is any chance of
file getting corrupted at the time of jaring the file? Please guide
me.

Thanks in advance,
Roopa.

Hi Eric,

Hope you got solutions to your problem.If so please guide me how did u do solve it?I am creating an executable jar file butI don't have any
package in my application.

Working Directory
--------------
D:\Mp3ToRingTone
Main Class is :mp3Player

Contents of Manifest file
---------------------
Manifest-Version: 1.0
Main-Class: mp3player
Created-By: Roopa

<I have left 2 blank lines>

when i run
java mp3player it launch the application without any problem

Command used to Buid the Jar file
---------------
jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class

Execute the Jar
java -jar MyRingRone.jar

I get the following error Exception in thread "main"
java.lang.NoClassDefFoundError: MyFileFilter

MyFileFilter is class, which i am using in mp3player.java. And when i unpack the jar file MyFileFilter.class exists. I don't understand what is the problem.


Roopa,

Note that a NoClassDefFoundError is different from a
ClassNotFoundException. An ClassNotFoundException usually indicates a
classpath problem. A NoClassDefFoundError indicates a more complex
problem, e.g., a corrupt or incompatible class file.

Ray

--
XML is the programmer's duct tape. [/b]
--
roopa_gh
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jul 17 '05 #8

P: n/a
roopa_gh wrote:
Hi Ray,

Thanks for your kind response.
You said A NoClassDefFoundError indicates a more complex
problem, e.g., a corrupt or incompatible class file.

But my application works fine without jar. Is there is any chance of
file getting corrupted at the time of jaring the file? Please guide
me.


Roopa,

I would try these two things:

1) Post exactly what you have done to create the jar file, starting from
nothing but the source code. Include details like the file system
structure, the manifest file, etc. (Note that your OP claimed that
MyFileFilter.class was in the jar file but it was not in the command you
used to create the jar.) There have been a couple of recent posts like
this, search Google for a guideline.

2) Create an empty directory and unpack your jar there using the jar
program (use the x option). Set the classpath to the classpath in your
manifest prepended by the current directory. Try to execute your main
class from the manifest.

Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #9

P: n/a
I would try these two things:

1) Post exactly what you have done to create the jar file, startin
from
nothing but the source code. Include details like the file system
structure, the manifest file, etc. (Note that your OP claimed that
MyFileFilter.class was in the jar file but it was not in the comman
you
used to create the jar.) There have been a couple of recent post
like
this, search Google for a guideline.

2) Create an empty directory and unpack your jar there using the jar
program (use the x option). Set the classpath to the classpath i
your
manifest prepended by the current directory. Try to execute your main
class from the manifest.

Ray

Hi Ray,

Thanks for the guidence.With your guidence i am able to solve th
problem. Now i am able to lunch my application with jar file. I hav
stucked with other problem

In my application i am using third party tool.
For ex: ThirdPartyTool.jar which i am placing under D:\Roopa

And I have java application which i have jared say MyApplication.jar
This also i placed under D:\Roopa.

when i lunch the application with the command
java -jar MyApplication.jar working fine.

But in my application for conversion of file it has to invok
"ThirdPartyTool.jar".

so i am setting classpath="%CLASSPATH%";D:\Roopa\ThirdPartyTool.ja r;
and then running java -jar Myapplication.jar it launches th
application but conversion is not happening.

But it works fine without jar. when i run
java MainClass launches and conversion takes place.
where i am going wrong. Please guide me.

Thanks for your time.
Roopa.


--
XML is the programmer's duct tape. [/B
-
roopa_g
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.