SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:Are you sure that's the class path? Not something with Documents and Settings in it? If so, you must put double quotes around the entire class path. Otherwise, the shell (command prompt) will see only the part until the space as the class path, and the next part ("and") as the next argument for java, which is then treated as the main class.
Jeff Verdegan wrote:Example 1, no package:
C:/classes/MyClass.class exists
java -cp C:/classes MyClass
Example 2, MyClass is declared package com.me;
C:/classes/com/me/MyClass.class exists
java -cp C:/classes com.me.MyClass
Note that in #2, you cannot do something like java -cp C:/classses/com/me MyClass. You must provide the full package name, and the root of that package must be inside a classpath root.
If you're still having trouble, copy/paste the exact, complete error message, and indicate clearly and precisely (like the above) what you did.
Kee Kee moon wrote:
After posting the question on this web site, I kept doing research. I did make it full path.
like:
java -classpath C:\..\..\.. app.works.MyApps -argFile C:\..\..\MyApps.property. But it is sill not working. It run on eclipse, so I am sure it is not the problem of program.
The errors as below:
Exception in thread "main" java.lang.NoClassDefFoundError: apps/works/MyApps
Caused by: java.lang.ClassNotFoundException: apps.works.MyApps
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)
Could not find the main class: apps.works.MyApps Program will exit
Jeff Verdegan wrote:
Kee Kee moon wrote:
After posting the question on this web site, I kept doing research. I did make it full path.
like:
java -classpath C:\..\..\.. app.works.MyApps -argFile C:\..\..\MyApps.property. But it is sill not working. It run on eclipse, so I am sure it is not the problem of program.
The errors as below:
Exception in thread "main" java.lang.NoClassDefFoundError: apps/works/MyApps
Caused by: java.lang.ClassNotFoundException: apps.works.MyApps
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)
Could not find the main class: apps.works.MyApps Program will exit
Okay, first, C:\.. makes no sense. You can't go above the root directory. I don't know what you're trying to do there.
Second you haven't provided enough information. What directory are you in when you run this command? What directory is your .class file in? What is the package statement at the top of that class's .java file?
The more information you provide, and the more clearly you provide it, the easier it is for others to understand your problem and provide advice.
Jeff Verdegan wrote:I'm sorry, but you don't appear to be paying attention to or understanding what I'm saying. You're not providing answers to the specific questions I asked, and you completely missed the point of what I said about ".." from the root directory. There's nothing more I can do to help you. Good luck.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:cd to your C:\apps\workspace\TestBatch\src directory.
type:
java launchapps.HelloWorld
Jeff Verdegan wrote:
fred rosenberger wrote:cd to your C:\apps\workspace\TestBatch\src directory.
type:
java launchapps.HelloWorld
You may still need an explicit classpath arg. If you have a CLASSPATH environment variable defined (which you shouldn't--there's no good reason to, but some stuff like QuickTime sets it on installation), and if it doesn't contain "dot" (current directory) then the above won't work.
So either :
1) cd as sugested and run
java -cp . launchapps.HelloWorld
or
2) From anywhere you choose, no special cd required, do
java -cp C:/apps/workspace/TestBatch/src launchapps.HelloWorld
The point is that the parent directory of launchapps needs to be in your classpath, whether it's absolute or relative.
Jeff Verdegan wrote:
fred rosenberger wrote:cd to your C:\apps\workspace\TestBatch\src directory.
type:
java launchapps.HelloWorld
You may still need an explicit classpath arg. If you have a CLASSPATH environment variable defined (which you shouldn't--there's no good reason to, but some stuff like QuickTime sets it on installation), and if it doesn't contain "dot" (current directory) then the above won't work.
So either :
1) cd as sugested and run
java -cp . launchapps.HelloWorld
or
2) From anywhere you choose, no special cd required, do
java -cp C:/apps/workspace/TestBatch/src launchapps.HelloWorld
The point is that the parent directory of launchapps needs to be in your classpath, whether it's absolute or relative.
| Consider Paul's rocket mass heater. |