473,769 Members | 7,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=$CLAS SPATH:.:/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.prin tln( "test.main( ) Hey there!");

}
catch (Exception e)
{
e.printStackTra ce();
}
}
}

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

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.NoCla ssDefFoundError :
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 11544
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.NoCla ssDefFoundError :
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.s pam.com.spam> wrote in message news:<JN******* *************@t wister.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.NoCla ssDefFoundError :
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:\Mp3ToRingTon e
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.NoCla ssDefFoundError : MyFileFilter

MyFileFilter is class, which i am using in mp3player.java. And when
unpack the jar file MyFileFilter.cl ass 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.NoCla ssDefFoundError :
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.codecomm ents.com> wrote in message news:<4b******* *************** ********@news.t henewsgroups.co m>...
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:\Mp3ToRingTon e
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.NoCla ssDefFoundError : MyFileFilter

MyFileFilter is class, which i am using in mp3player.java. And when i
unpack the jar file MyFileFilter.cl ass 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.NoCla ssDefFoundError :
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:\Mp3ToRingTon e
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.NoCla ssDefFoundError : MyFileFilter

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


Roopa,

Note that a NoClassDefFound Error is different from a
ClassNotFoundEx ception. An ClassNotFoundEx ception usually indicates a
classpath problem. A NoClassDefFound Error 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.codecomm ents.com> wrote in messag
news:<4b******* *************** ********@news.t henewsgroups.co m>...
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:\Mp3ToRingTon e
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.NoCla ssDefFoundError : MyFileFilter

MyFileFilter is class, which i am using in mp3player.java. And whe i unpack the jar file MyFileFilter.cl ass 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 NoClassDefFound Error 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:\Mp3ToRingTon e
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.NoCla ssDefFoundError : MyFileFilter

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


Roopa,

Note that a NoClassDefFound Error is different from a
ClassNotFoundEx ception. An ClassNotFoundEx ception usually indicates a
classpath problem. A NoClassDefFound Error 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 NoClassDefFound Error 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.cl ass 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.cl ass 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.j ar
This also i placed under D:\Roopa.

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

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

so i am setting classpath="%CLA SSPATH%";D:\Roo pa\ThirdPartyTo ol.jar;
and then running java -jar Myapplication.j ar 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
2106
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 add-in to another computer? Thanks a lot -------------------------------- From: Kelly ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/)
1
4851
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 --------------------- #include "stdafx.h" using namespace System::Reflection; using namespace System::Runtime::CompilerServices;
1
3837
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 /i c:\program files\cccc\aaa.exe -i "c:\program files\cccc\aaa.exe" /i c:\program files\cccc\aaa.exe -i %1
3
4102
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. 1. I have very much data to be incorporated into the executable file. I have to add much data into my developed program into 2 Combo Boxes and 1 List Box control. For that i have created an xml element with all of the
4
2072
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). Requirements are to create thumbnails for even these banner-sized images, but PHP + GD + = too much memory. I'm trying to prove that it is undoable, though the suggestion was to do a command-line GD call to the image instead of using the PHP...
2
7039
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 fine, every time. But, if I access on it's public IP, from my office workstation, from home, over the VPN, a test machine on ADSL, or whatever else you please, it fails. But only about 60% of the time. I have tried everything to pin this down....
1
1593
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 separate text file ). i THOUGHT everything was fine. When i have my code open in VS 6.0 i build and compile it, and everything works fine, BUT when i run the executable file, the printout to the console is correct, but the printout to the file doesn't...
2
1532
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 decrypt the same file? How secure is to hide an hexadecimal number to be used as password or key inside an executable file? String are easy to find. Any help is appreciated,
4
5625
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++ and C# code) into a solution from visual studio .net 2003. In out solution we have a project implementing a pretty complicated math algorithm. This component usally work very well. But in a couple weeks ago, a user found a case that our...
4
2351
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 necessary. for instance, have a button somewhere on the desktop that they can just click it and the executable will stop. Or inset some lines of code that would specify a 'button' sequence that the user can press on the keyboard that would trigger...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10048
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.