Results 1 to 2 of 2
  1. #1
    dangr is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default 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

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    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

  1. How to convert a String to upper case
    By Valeriano in forum New To Java
    Replies: 16
    Last Post: 03-01-2010, 12:39 PM
  2. How to Correctly learn java? Books? Tutorial?
    By elektronika in forum New To Java
    Replies: 7
    Last Post: 12-10-2009, 11:23 AM
  3. Help with sphere.java - not coming out correctly
    By JavaInLove in forum Java 2D
    Replies: 3
    Last Post: 03-17-2009, 08:38 PM
  4. How Do I Embed Java Correctly To A Web Page
    By abcd in forum Java Applets
    Replies: 7
    Last Post: 01-28-2008, 07:53 AM
  5. how to use class in upper folder
    By osval in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •