Results 1 to 4 of 4
- 01-23-2011, 05:10 AM #1
Senior Member
- Join Date
- Feb 2009
- Posts
- 117
- Rep Power
- 0
cannot run the class file using the java command
hi. I am having trouble running simple codes due to some problems.
I have my class here name MyClass.java inside a package
and I have some folders structured like thisJava Code:package com.sm; class MyClass { public static void main (String[] args) { System.out.println("FUBAR"); } }
MyProject> source,classes
source>com>sm>MyClass.java
classes>com>sm>MyClass.class
I was able compile the application and put it in the classes>com>sm folder using this code
ok that is all fine, but the problem is I cannot run the application using the java command. what i do is I go to the folder where my class file is and then try to do "java MyClass" but it seems like it is not accepting the file it gives meJava Code:javac -d classes (diretoryToMyJavaFile)/MyClass.java
what I did recompiled the simple file without the package declaration up top and it worked. seems like it does not want to be included in the package I put it into. are there any problems with the package name? or are there certain rules that I need to follow so I can give my java file a package declaration?Java Code:Exception in thread "main" java.lang.NoClassDefFoundError: MyClass (wrong name: com/sm/MyClass)
-
What if you try to run it from the classes directory via
Java Code:java com.sm.MyClass
- 01-23-2011, 05:36 AM #3
Senior Member
- Join Date
- Feb 2009
- Posts
- 117
- Rep Power
- 0
that did it! thanks! :DI guess need to read more about packages :)
anyway thanks again
regards,
simon
-
Similar Threads
-
cannot find the class file when running the java command
By kulangotski in forum New To JavaReplies: 4Last Post: 01-18-2011, 11:34 AM -
converting java class file to exe file
By satheeshtech in forum Advanced JavaReplies: 5Last Post: 07-18-2009, 11:47 PM -
Is there any way to run java file through command prompt of .jar
By sachin.parnami in forum New To JavaReplies: 2Last Post: 12-03-2008, 01:24 PM -
Filter a file in java (unix cut command equivalent)
By marcosabel in forum New To JavaReplies: 0Last Post: 02-11-2008, 07:26 PM -
Unable to execute command line command in java
By LordSM in forum New To JavaReplies: 1Last Post: 08-08-2007, 12:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks