• Post Reply Bookmark Topic Watch Topic
  • New Topic

java app launch on console  RSS feed

 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have java program and I always run on eclipse and it works.
As now I need to run on windows console, I do as below:

java -classpath C:\eclipse\workspace\MyApps\bin\myappsclass MyApps -fileArgs C:\myapps.Property

and got errors like:
Exception in thread "main" java.lang.NoClassDefFoundError: and
Caused by: java.lang.ClassNotFoundException: and
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: and. Program will exit.

Please help.
Thanks a lot.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



Thank you for your input. I did try to move my app to c:\apps\workspace and run on eclipse. It works.
Then, I set the class to c:\apps\workspace......, but I still got the same errors.

Please help.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



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
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



I did try on C:/../../.. as well. but failed.

I have tried anything that I could think of..
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




I create a new program HelloWorld:

package launchapps;

public class HelloWorld {
public static void main(String [] args) {
System.out.println("Hello World!!!");
}
}


I ran on eclipse and it works. the class name is HellowWorld.class. It is in C:\apps\workspace\TestBatch\src\launchapps directory.

I run on windows command line and got errors as below:

C:\apps\workspace\TestBatch\src\launchapps>java apps.workspace.TestBatch.src.lau
nchapps.HellowWorld
Exception in thread "main" java.lang.NoClassDefFoundError: apps/workspace/TestBatch/src/launchapps/HellowWorld
Caused by: java.lang.ClassNotFoundException: apps.workspace.TestBatch.src.launchapps.HellowWorld
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.workspace.TestBatch.src.launchapps.HellowWorld. Program will exit.



 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cd to your C:\apps\workspace\TestBatch\src directory.

type:

java launchapps.HelloWorld
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.





Thank you very much. It works.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Thank you very much for your help.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. Glad you got it straightened out.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!