0

my program consist of

"javax.mail.jar"

and a simple myProgram.java (Contain Main class) ("package:com.test.myprogram")

and anotherProgram.java (contain Main class) ("package:com.test.myprogram")

I have converted it to "myprogram.jar" file

how do I run "myProgram.java" in shell? using "myprogram.jar"

isme
  • 190
  • 2
  • 3
  • 18
  • http://stackoverflow.com/questions/5774970/run-jar-file-in-command-prompt – Kamal Abdullasoy Dec 08 '16 at 09:06
  • 3
    Possible duplicate of [How to run a JAR file](http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file) – Ruben Steins Dec 08 '16 at 09:12
  • Are you asking how to run a JAR that has as a dependency another JAR? If so, you need to specify how you generated that JAR and what error message you're getting. Please, check [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) to improve your question. – Tom Dec 08 '16 at 10:44

2 Answers2

1

If your application is in (say) "myprogram.jar" and it depends on "javax.mail.jar", then you would run it like this:

$ java -cp myprogram.jar:javax.mail.jar com.test.myprogram.Main

(On Windows, you need to use ; instead of : as the classpath separator.)

However, it doesn't make a lot of sense to have "myProgram.java" and "anotherProgram.java" BOTH declare a Main class ... by which I assume you mean a class called Main. The problem is that since both versions of the Main class are in the same package, compiling one source file will overwrite the Main class produced when you compile the other source file.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
-1
 java -classpath yourjarfilename.jar yourpackagename.classname
kuttan pillai
  • 118
  • 1
  • 15
Sudharasan D
  • 119
  • 5