0

I have created a program in Java, but it is not taking the inputs correctly in edit-plus(compiler) so now I want it to run in cmd. My JSK file is at : C:\Program Files\Java\jdk1.7.0_21\bin and my Java file is at: C:\TurboC4\TC\java new programs

Please tell me the steps to run it in cmd.

n00begon
3,5123 gold badges31 silver badges42 bronze badges
asked Oct 2, 2013 at 21:57

3 Answers 3

3

On the command line use:

java -jar path/to/your/jar_file.jar

if you do not have a jar file, than you have to compile first your Java classes:

javac -g Foo.java

if you have just a single file (containing a static void main()) than you can simply run it with:

java path/to/your/compiled_class_file [<command line args>, ...] 

Note: Run the command above without .class extension. i.e.

java Foo

if you want to generate a jar file from your compiled .class files run:

jar cf jar-file input-file(s)

However, I would recommend you to use a IDE that compiles, packs and runs your code for you automatically with one click. i.e. IntelliJ or Eclipse

answered Oct 2, 2013 at 21:59
Sign up to request clarification or add additional context in comments.

Comments

0

If your class is not into a package and is compiled as java.class in C:\TurboC4\TC\:

cd C:\TurboC4\TC\
C:\Program Files\Java\jdk1.7.0_21\bin java
answered Oct 2, 2013 at 22:03

Comments

0

If you just want to run your single java class as a command line program, then the answer is in This question.

Example:

java my.class.HelloWorld

If you have compiled an entire java project into a JAR file, check this Stackoverflow question for the answer.

Example:

java -cp c:\location_of_jar\myjar.jar com.mypackage.myClass
answered Oct 2, 2013 at 22:07

Comments

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.