943,747 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1581
  • Java RSS
Sep 27th, 2009
0

Compiling a PACKAGE using javac

Expand Post »
I wrote a Java program, and it successfully compiles and runs in NetBeans, but I'm not able to do the same in the command line, on Windows XP.

It works ok with 1 class, but when I have few files 'package' I have a problems.

1.Start -> run -> cmd
2.Go to dir:
cd C:\Program Files\Java\jdk1.6.0_16\bin

3.Now I'm trying to compile a package:
(my package is this:
Java Syntax (Toggle Plain Text)
  1. test/Main.java
  2. test/Hotel.java

I do compile my package:
javac test\*.java

Then I try to run compiled package:
java test\Main
Also trying:
java test

But allways is errors only:
Java Syntax (Toggle Plain Text)
  1. C:\Program Files\Java\jdk1.6.0_16\bin>java test\Main
  2. Exception in thread "main" java.lang.NoClassDefFoundError: test\Main/class
  3. Caused by: java.lang.ClassNotFoundException: test\Main.class
  4. at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  5. at java.security.AccessController.doPrivileged(Native Method)
  6. at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  7. at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
  8. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
  9. at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
  10. at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
  11. Could not find the main class: test\Main.class. Program will exit.


===============
Source codes

JAVA Syntax (Toggle Plain Text)
  1. package test;
  2. public class Main {
  3. static int SPEED = 300; // ms
  4.  
  5. public static void main(String[] args) {
  6. // TODO code application logic here
  7. System.out.println("Loading");
  8.  
  9. // Run hotels'live
  10. Hotel.do_live(SPEED);
  11. }
  12. }

JAVA Syntax (Toggle Plain Text)
  1. package test;
  2.  
  3. public class Hotel {
  4. public static void do_live(int wait)
  5. {
  6. System.out.println("\n\rHotel was finished");
  7. }
  8. }


------------
If I have only one file(class), then all is ok:
Java Syntax (Toggle Plain Text)
  1. javac TestJava.java
  2. java TestJava

So how I can build the Java package in command line.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Xamas is offline Offline
15 posts
since Apr 2009
Sep 28th, 2009
0

Re: Compiling a PACKAGE using javac

Java Syntax (Toggle Plain Text)
  1. java test.Main
not
Java Syntax (Toggle Plain Text)
  1. java test\Main
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Sep 28th, 2009
0

Re: Compiling a PACKAGE using javac

Thanks. I would never believed that it was so easy to fix
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Xamas is offline Offline
15 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: no-Cache Control in I.E causing back browser to show page not found
Next Thread in Java Forum Timeline: prefix,Postfix Notations





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC