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

    Default java run correctly in the upper directory

    I compile By javac some java sources with this sintax:

    javac -cp .;c:\com
    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


  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    this has to do with the file being in the java 'package'

    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, 01:39 PM
  2. How to Correctly learn java? Books? Tutorial?
    By elektronika in forum New To Java
    Replies: 7
    Last Post: 12-10-2009, 12:23 PM
  3. Help with - not coming out correctly
    By JavaInLove in forum Java 2D
    Replies: 3
    Last Post: 03-17-2009, 09: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, 08:53 AM
  5. how to use class in upper folder
    By osval in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09: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