0

I had a compilable java file under Eclipse, the source file is under the directory like

/home/workspace/testApplication/src/Test/test.java

I can run it from Eclipse by clicking "run as Java application". But if I want to run this problem from command line, how to do that?

asked Dec 30, 2011 at 3:06

1 Answer 1

1

Something like this:

java -cp /home/workspace/testApplication/bin Test.test <app's command line args>

The "-cp ..." option gives the classpath, and it should include the absolute pathname of the directory tree into which Eclipse is writing ".class" files. The "Test.test" argument is the fully qualified class name of your application's entrypoint class; i.e. the one with the "main" method that starts the app.

If your application depends on other JAR files etc, they will need to be added to the classpath.


I should point out that you are violating the Java naming conventions. A package name should be all lowercase, and a class name should be camel case with the first character being an uppercase letter.

answered Dec 30, 2011 at 3:15
Sign up to request clarification or add additional context in comments.

4 Comments

This is assuming that "Test" is a package and not the "source folder" in eclipse.
@Pangea - yes. I'm assuming that "src" is the source folder, not "src/Test".
Stephen, in my example, the "Test" is used for the package name. For the Test.test in your answer, are you referring to test.java in my original post? In my example, test.java is the one that has the "main" method. Thanks for clarification.
@user785099 Yes, Test.test is the fully qualified name of the class with the main method. See this Oracle technote for Windows: Setting the class path ~nix. You will generally want to avoid the CLASSPATH environment variable.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.