Results 1 to 2 of 2
- 01-22-2010, 08:31 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 5
- Rep Power
- 0
java run correctly in the upper directory
I compile By javac some java sources with this sintax:
javac -cp .;c:\com MenuExample.java
this source code are in the directory C:\com\a1\
the compiler makes 2 classes: MenuExample.class and MenuExample$1.class
now if I run it, in the same directory, with
java -cp .;c:\com MenuExample
there is a error messagge:
java.lang.NoClassDefFoundError: MenuExample (wrong name)
if I go to the upper directory (C:\com) and I entry
java a1.MenuExample the program run normally.
I not understand the reason of this behavior.
Thanks in advance
Dan
- 01-29-2010, 07:52 PM #2
this has to do with the file MenuExample.java being in the java 'package' com.ai.MenuExample.
the javac compiler is more forgiving about where it is invoked on the file system path, as it is reading a .java file and generating a .class file. where as the java VM to run this .class file needs to work from the top level of the class path, which is the folder that contains (in this case) the "com" folder. it is also confusing at first because a java package corresponds to a folder on the file system in the sources.
Similar Threads
-
How to convert a String to upper case
By Valeriano in forum New To JavaReplies: 16Last Post: 03-01-2010, 01:39 PM -
How to Correctly learn java? Books? Tutorial?
By elektronika in forum New To JavaReplies: 7Last Post: 12-10-2009, 12:23 PM -
Help with sphere.java - not coming out correctly
By JavaInLove in forum Java 2DReplies: 3Last Post: 03-17-2009, 09:38 PM -
How Do I Embed Java Correctly To A Web Page
By abcd in forum Java AppletsReplies: 7Last Post: 01-28-2008, 08:53 AM -
how to use class in upper folder
By osval in forum New To JavaReplies: 1Last Post: 08-06-2007, 09:55 PM
Bookmarks