• Post Reply Bookmark Topic Watch Topic
  • New Topic

trying to run a .jar file in command prompt  RSS feed

 
Arian Gerryts
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to run a jar file using my command prompt (Windows XP) but get NoClassDefFoundError.

I have my DateAndTime.class file in a folder called dateandtime and also indicated a package called dateandtime in the source file.

Outside the folder I have a manifest.mf file with specification.

Main-Class: dateandtime.DateAndTime


I put this in the command line.

jar cmf manifest.mf myJarFile.jar dateandtime


and this creates the myJarFile.jar in the same folder as manifest.mf.

When I try to run this jar file however I get the NoClassDefFoundError.

Exception in thread "main" java.lang.NoClassDefFoundError: dateandtime/DateAndTime (wrong name: DateAndTime)


The name however is not wrong.

If I have all the classes in the same directory with no package specified then the .jar file runs fine but as soon as I try to specify a package, even though myJarFile.jar was created I get the error.

Why is that?

Regards
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dumb question - did you have package declaration in your program?
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you run jar -cvmf you will get more information about why it doesn't work.

Check the following:

The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


see http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Check what is inside the JAR with the command: jar tvf myJarFile.jar

you should see that there is a file DateAndTime.class in the subdirectory dateandtime.

I suspect that DateAndTime.class might be in the root directory of the jar, instead of in a subdirectory dateandtime.

You should run it with the -jar option: java -jar myJarFile.jar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!