This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java commandline doesn't work

 
christine clarin
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, i already made javac work in compiling my java codes. i had two classpaths set: one for my packages and one for my jar file. this is what i used:

javac -cp <path1>:<path2> codetocompile.java

and it worked. the codetocompile.java already has the main code that i want. it compiles as well i.e., it releases a .class file. however, when i run it with

java codetocompile

it tells me that i have no main in that code and noclassdeffound exception is thrown. i can't run my program!how do i solve this? thanks! i really need some help =(
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15203
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1: "it tells me that i have no main in that code..."

Do you have a 'main' method in your class that has the following signature:

public static void main(String[] args)

Note: it must be public, static, void, the name must be 'main' and it must have a String array as a parameter.

2: "...and noclassdeffound exception is thrown"

You have to use the "-cp ..." also when you run the program, not just when you compile the program. Make sure the directory that contains the class file is included in the classpath.
[ April 19, 2007: Message edited by: Jesper Young ]
 
christine clarin
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, yes I have public static void main (String args[])present in my codetocompile java...i also already used this:
java -cp path1 : path2 codetocompile

but it still gives me this:
Exception in thread "main" java.lang.NoClassDefFoundError: InfectedCellCount

why is this so? thank you!
[ April 19, 2007: Message edited by: christine clarin ]
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might be totally wrong, and I can't test it right at the moment, but I've seen this happen when you type in the file extension at the command line. Like, if you type "java codeToRun.class" it gives you that error, but if you just type "java codeToRun" it should work fine... I think that's what happened in my case.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by christine clarin:
i also already used this:
java -cp path1 : path2 codetocompile


Unless you have enclosed the whole thing in quotes, there should be no spaces in the classpath.
i.e. it should be
java -cp path1:path2 codetocompile


If it still doesn't work when you've removed the spaces, then post the actual command line you are using and tell us where the InfectedCellCount class is.

[ April 19, 2007: Message edited by: Joanne Neal ]
[ April 19, 2007: Message edited by: Joanne Neal ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic