Results 1 to 4 of 4
  1. #1
    meandthebros is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default Compile and run a whole project

    Hi everybody!

    I have a little problem with the "java" command.

    I have a project with 14 .java files (like Application.java, MyLogger.java, etc.). I can compile them with "javac *.java" and after compiling i got the .class files.
    And the problem is, that i cannot run the program from console (in eclipse i can run the program, but i need to make it work in console too).
    I type in "java Application" and then i get this error message:
    Java Code:
    Exception in thread "main" java.land.NoclassDefFoundError: Application (wrong name: skeleton/Application)[INDENT]
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java,security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)[/INDENT]
    Could not fint the main class: Application. Program will exit.

    My Application.java looks like:
    Java Code:
    package skeleton;
    
    import java.*;
    import java.io.*;
    import java.util.*;
    
    public class Application {
    //...
    public static void main(String[] args) {
    //...
    }
    }
    What should i do, to make work all of this "run whole project" thing work?
    I googled everything, even the paradise and hell, but nothing.

    Please help me!

    Thanks,
    Tom

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    The java command requires you to name the class. ANd the name of a class includes the package. So the command should be more like:

    Java Code:
    java skeleton.Application

    This leaves the question of where the java executable will look to find the skeleton package. (it knows how to find skeleton.Applcation once it has located the folder corresponding to the skeleton package). The java executable looks for packages in a series of locations known, collectively, as the classpath.

    The classpath is typically specified as part of the java command. (and javac for that matter). So if you were at the command line in the folder containing the skeleton folder, the command would be:

    Java Code:
    java -cp . skeleton.Application

    The "-cp ." bit means "the classpath is this directory". So java will look in the current directory for a skeleton folder and it will find it. It will then look for Application.class within the skeleton folder and it will find it. java will be happy.

    (If you execute java from somewhere else then the -cp part will be different. Full details at the java man page.)

  3. #3
    meandthebros is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    Dear pbockway2!

    Thanks for your help, it worked!

    Tom

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

Similar Threads

  1. Adding a project to an existing project
    By Seijuro in forum NetBeans
    Replies: 4
    Last Post: 08-08-2010, 11:15 AM
  2. How do I compile this project?
    By scooby in forum CLDC and MIDP
    Replies: 5
    Last Post: 04-15-2010, 03:51 PM
  3. Replies: 1
    Last Post: 12-18-2009, 07:18 PM
  4. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 09:12 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
  •