Compiling a PACKAGE using javac

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2009
Posts: 14
Reputation: Xamas is an unknown quantity at this point 
Solved Threads: 0
Xamas Xamas is offline Offline
Newbie Poster

Compiling a PACKAGE using javac

 
0
  #1
Sep 27th, 2009
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:
  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:
  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

  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. }

  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:
  1. javac TestJava.java
  2. java TestJava

So how I can build the Java package in command line.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Compiling a PACKAGE using javac

 
0
  #2
Sep 28th, 2009
  1. java test.Main
not
  1. java test\Main
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 14
Reputation: Xamas is an unknown quantity at this point 
Solved Threads: 0
Xamas Xamas is offline Offline
Newbie Poster

Re: Compiling a PACKAGE using javac

 
0
  #3
Sep 28th, 2009
Thanks. I would never believed that it was so easy to fix
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 445 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC