472,805 Members | 3,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Executable jar file problem

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
9 11460
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kelly Xie via .NET 247 | last post by:
Hi, I am building an add-in to the .NET framework using C#. I need to call an external executable file. It works fine with the computer I am working now. How can I make it work when I install the...
1
by: Scott Chang | last post by:
Hi all, I loaded the following program 'HelloMCPP' to my MS VC++ .NET (2002) that is installed on my Windows XP Professional PC: ------------------------------------- AssemblyInfo.cpp...
1
by: yxq | last post by:
Hello, I want to make a utility to clean Registry, my problem is that: How to get actual executable file path? There are lots of command line modes in Registry: c:\program files\cccc\aaa.exe...
3
by: SpIcH | last post by:
Hi All, This is all about protecting my data in Executable file. I have developed a program in Visual Basic .NET 2002. I have many questions in mind... please help me to complete my project. ...
4
by: comp.lang.php | last post by:
I downloaded the tarball and while was able to compile within PHP with no problems, I am having memory timeout issues involving image manipulation with extremely large images (800K - 2mb). ...
2
by: mudge | last post by:
Hi, I'm getting some very strange problems with some C# code. We're running an ASP.NET application on a local server in a DMZ. If I access it using the internal address, the application works...
1
by: manontheedge | last post by:
i'm using microsoft visual studio 6.0, and i have a program that reads in a text file, then looks for a variety of things, sorts them into categories, and prints them out ( to the console AND a...
2
by: Nicola Taibi | last post by:
Hi, In a visual basic .net 2003 application I use an hexadecimal number to encrypt a file as a symmetric key. Is it possible to detect, within the executable, the number above to consequently...
4
by: linda.chen | last post by:
Greeting. We have a 6 year old application, which contains both managed (C#) and unmanaged code (C++). For all the new components we try to create them in C#. We build all projects (both C++...
4
by: Perl Beginner | last post by:
i have created an automation program using Perl (Win32). i converted the perl script to an executable file. what i would like to do is have a way for the user to easily kill the executable file if...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.