Jump to content

  • Log In with Google      Sign In   
  • Create Account


[java] compile/run with packages


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 gdalston   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 January 2001 - 09:17 PM

I''m compiling, jarring and running from the command line. If I don''t have my classes in a package, then everything works fine, i.e. I use javac,jar and java to compile, make a jar file, and then run a class from that jar. But if I put my classes in a package, they won''t run. It says something like "Exception in main: Editor (package/Editor has wrong name)." So it looks like the class files have the package name in them correctly. When I open up the jar file with winzip, I notice that they are not in the path /package, which they should be. So my question is how do I jar these up into the correct format? thanks

Sponsor:

#2 bobbin   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 January 2001 - 10:51 PM

If your package was called ''myClasses'' then your classes would have to be in a directory ''myClasses/''
and I would then run with ''java myClasses.className''.
Yes the class files must live in a directory with the same name as their package, and this directory must be included in your class_path...

#3 gdalston   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 January 2001 - 07:55 AM

Thats the problem... the classes are not in the correct path within the jar file. So my question is how do I get them to have the correct path within the jar file?

#4 c_wraith   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 January 2001 - 09:18 AM

You need to create the jar file from the unnamed package level...

If you had packageA and packageB, and wanted them both in one jar file, you''d do something like this, from the directory which has the packageA and packageB directories as immediate subdirectories:

jar cvf packages.jar packageA/*.class packageB/*.class

Or, *.* if you want other files, etc...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS