BicaBicudo
BicaBicudo

Reputation: 307

javac e java command-line

Assuming I have the following folder structure:

Which command 'java.exe' I would use to run the class MyClass.class, admitting that I was in folder 'source'?

Upvotes: 0

Views: 126

Answers (3)

Franklin
Franklin

Reputation: 1801

java -cp myProject/classes com.wickedlysmart.MyClass

Upvotes: 1

sheidaei
sheidaei

Reputation: 10342

Whatever command you are using for running MyClass.class in its folder plus navigation to the Myclass.class.

Let's say you are using

java MyClass 

to run it from it's directory. Now you have to use

java -cp ../../myproject/classes com.wickedlysmart.MyClass

to run from some other directory

Upvotes: 1

Mark Rotteveel
Mark Rotteveel

Reputation: 109045

You need to specify the classpath for the classes folder, so you need to do:

java -cp ../classes com.wickedlysmart.MyClass

Or

java -cp <full-path-to>/classes com.wickedlysmart.MyClass

Note: This is assuming that you made an error in your post with the hierarchy with having com and wickedlysmart on the same level. If they should be on the same level, remove the com. from above examples.

Upvotes: 3

Related Questions