I have a java file simpleMail.java and a jar file java-mail-1.4.jar (which is used in simpleMail.java). What I want to do is make an executable jar file out of these files and run on cmd.
Asked
Active
Viewed 453 times
-1
-
Sorry, this is not how StackOverflow works. Please take the [tour], visit the [help] and read [Ask] to learn how to use this site effectively. – Jim Garrison Mar 23 '18 at 05:02
-
Are u using intellij idea? – SteelToe Mar 23 '18 at 05:02
-
@SteelToe no just notepad. i need to run it on cmd – Anuj Victor Mar 23 '18 at 05:04
-
If u would use intellij j, they have an option to generate a jar with all dependencies – SteelToe Mar 23 '18 at 05:05
-
@JimGarrison i'll be glad if you'll help me out for an answer. – Anuj Victor Mar 23 '18 at 05:06
-
@AnujVictor google around for "Java uberjar" and rephrase your question. What have you tried? – Bob Kuhar Mar 23 '18 at 05:06
-
@SteelToe so there isn't any way without it? – Anuj Victor Mar 23 '18 at 05:07
-
I believe u need a fat jar. Check this out. https://stackoverflow.com/questions/39089189/how-to-make-a-fat-jar-of-a-maven-project – Nelson Christos Mar 23 '18 at 05:18
-
Possible duplicate of [How can you package an executable jar with a portable JRE?](https://stackoverflow.com/questions/664858/how-can-you-package-an-executable-jar-with-a-portable-jre) – Piro Mar 23 '18 at 05:20
1 Answers
2
Step 1. create manifest.txt file as Main-Class: Main-Class-Name
Step2. compile all classes.
Step 3. run JDK's jar.exe utility like:
jar cvfm JarName.jar manifest.txt .class cvfm is create a jar; show verbose output; specify the output jar file name; specify the manifest file name. (.class means all class files in the current directory.)
Step 4. specify jar dependency on classpath.
For detail refer http://www.skylit.com/javamethods/faqs/createjar.html

Manvi
- 1,136
- 2
- 18
- 41