Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #715 > unrolled thread

jar execution problem

Started bySascha <sascha_friederichs@web.de>
First post2011-05-25 23:25 +0800
Last post2011-05-26 06:46 +0800
Articles 5 — 4 participants

Back to article view | Back to comp.lang.java.help


Contents

  jar execution problem Sascha <sascha_friederichs@web.de> - 2011-05-25 23:25 +0800
    Re: jar execution problem Knute Johnson <nospam@knutejohnson.com> - 2011-05-25 08:48 -0700
      Re: jar execution problem Lew <noone@lewscanon.com> - 2011-05-25 12:29 -0400
    Re: jar execution problem Roedy Green <see_website@mindprod.com.invalid> - 2011-05-25 09:04 -0700
      Re: jar execution problem Sascha <sascha_friederichs@web.de> - 2011-05-26 06:46 +0800

#715 — jar execution problem

FromSascha <sascha_friederichs@web.de>
Date2011-05-25 23:25 +0800
Subjectjar execution problem
Message-ID<irj70i$2v6n$1@adenine.netfront.net>
Hello,

i got a problem with execution of jar files.


I used the following command to create a jar file.
jar -vcfm dice.jar MANIFEST.TXT dice

In the folder dice the Dice.class is located.

The file MANIFEST.TXT contains only the following line
Main-Class: Dice

When I try to execute the jar file with
java -jar dice.jar

I got the error message
Exception in thread "main" java.lang.NoClassDefFoundError: Dice

I hope somebody else got the same problem and can help me out.

Thanks in advance for the help.

--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

[toc] | [next] | [standalone]


#716

FromKnute Johnson <nospam@knutejohnson.com>
Date2011-05-25 08:48 -0700
Message-ID<ky9Dp.19523$ZM2.2437@newsfe19.iad>
In reply to#715
On 05/25/2011 08:25 AM, Sascha wrote:
> Hello,
>
> i got a problem with execution of jar files.
>
>
> I used the following command to create a jar file.
> jar -vcfm dice.jar MANIFEST.TXT dice
>
> In the folder dice the Dice.class is located.
>
> The file MANIFEST.TXT contains only the following line
> Main-Class: Dice
>
> When I try to execute the jar file with
> java -jar dice.jar
>
> I got the error message
> Exception in thread "main" java.lang.NoClassDefFoundError: Dice
>
> I hope somebody else got the same problem and can help me out.
>
> Thanks in advance for the help.
>
> --- Posted via news://freenews.netfront.net/ - Complaints to
> news@netfront.net ---

Does your Dice source file have a package statement?  If you are running 
the jar program from the directory above dice it will store the class 
files as dice/Dice.class and that must match with the package statement 
in the source file.

So as not to ask you a lot of questions, do this:

1) put your source files in the dice directory.
2) put a 'package dice;' statement in all source files
3) compile from the directory above dice with 'javac dice/Dice.java'
4) put the manifest file in dice and
    in it put the line 'Main-Class: dice.Dice'
5) run the jar program from the directory above dice with
    'jar -cvfm Dice.jar dice/manifest dice/*.class dice/anyotherfiles'
    I usually keep my manifest file in the same directory but it isn't 
necessary.

You can use the 'e' option and skip using a manifest file it the only 
thing in it is the Main-Class statement.

-- 

Knute Johnson
s/knute/nospam/

[toc] | [prev] | [next] | [standalone]


#718

FromLew <noone@lewscanon.com>
Date2011-05-25 12:29 -0400
Message-ID<irjao3$9lv$1@news.albasani.net>
In reply to#716
Knute Johnson wrote:
> Sascha wrote:
>> i [sic] got a problem with execution of jar [sic] files.
>>
>>
>> I used the following command to create a jar file.
>> jar -vcfm dice.jar MANIFEST.TXT dice
>>
>> In the folder dice the Dice.class is located.

There's your problem.

>> The file MANIFEST.TXT contains only the following line
>> Main-Class: Dice

And there, just as Knute said.

>> When I try to execute the jar file with
>> java -jar dice.jar

And there, also as Knute said.

>> I got the error message
>> Exception in thread "main" java.lang.NoClassDefFoundError: Dice
>>
>> I hope somebody else got the same problem and can help me out.

> Does your Dice source file have a package statement? If you are running the
> jar program from the directory above dice it will store the class files as
> dice/Dice.class and that must match with the package statement in the source
> file.
>
> So as not to ask you a lot of questions, do this:
>
> 1) put your source files in the dice directory.
> 2) put a 'package dice;' statement in all source files
> 3) compile from the directory above dice with 'javac dice/Dice.java'
> 4) put the manifest file in dice and
> in it put the line 'Main-Class: dice.Dice'
> 5) run the jar program from the directory above dice with
> 'jar -cvfm Dice.jar dice/manifest dice/*.class dice/anyotherfiles'
> I usually keep my manifest file in the same directory but it isn't necessary.
>
> You can use the 'e' option and skip using a manifest file it the only thing in
> it is the Main-Class statement.

You cannot do serious Java programming without packages, nor should you try. 
Study
<http://download.oracle.com/javase/tutorial/java/package/index.html>

For all known directory-based structures for serving up classfiles, the 
directory structure from some root in the classpath must match the package 
structure.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#717

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-05-25 09:04 -0700
Message-ID<d0aqt652d081akp9m3e76eldon1p379gf0@4ax.com>
In reply to#715
On Wed, 25 May 2011 23:25:05 +0800, Sascha <sascha_friederichs@web.de>
wrote, quoted or indirectly quoted someone who said :

>I got the error message
>Exception in thread "main" java.lang.NoClassDefFoundError: Dice

Put your class in a package.  null package is only for single-class
experimentation.


see http://mindprod.com/jgloss/jarexe.html
http://mindprod.com/jgloss/jar.html

for gotchas on creating jars

Manifests are picky about newline characters.

-- 
Roedy Green Canadian Mind Products
http://mindprod.com
How long did it take after the car was invented before owners understood 
cars would not work unless you regularly changed the oil and the tires?
We have gone 33 years and still it is rare to uncover a user who 
understands computers don't work without regular backups.

[toc] | [prev] | [next] | [standalone]


#719

FromSascha <sascha_friederichs@web.de>
Date2011-05-26 06:46 +0800
Message-ID<irk0ra$o72$1@adenine.netfront.net>
In reply to#717
Hello,

thank you Knute, Lew and Roedy.

The problem is solved. The missing package dice;
was the problem.

Thanks again for the quick help.

Regards,

Sascha

On 05/26/2011 12:04 AM, Roedy Green wrote:
> On Wed, 25 May 2011 23:25:05 +0800, Sascha<sascha_friederichs@web.de>
> wrote, quoted or indirectly quoted someone who said :
>
>> I got the error message
>> Exception in thread "main" java.lang.NoClassDefFoundError: Dice
>
> Put your class in a package.  null package is only for single-class
> experimentation.
>
>
> see http://mindprod.com/jgloss/jarexe.html
> http://mindprod.com/jgloss/jar.html
>
> for gotchas on creating jars
>
> Manifests are picky about newline characters.
>


--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.help


csiph-web