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,503
  • 3
  • 29
  • 42
ashish
  • 15
  • 4

3 Answers3

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

sockeqwe
  • 15,574
  • 24
  • 88
  • 144
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
Cedric Simon
  • 4,571
  • 4
  • 40
  • 52
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
Community
  • 1
  • 1
user1071914
  • 3,295
  • 11
  • 50
  • 76