banner



How To Create Batch File For Java Project

4 Answers 4

Because you are working in eclipse, this makes things easier. First, export the whole program as a executable jar. You can do this by going to Files>Export and then in the pop up go to Java>Runnable Jar. Then follow the steps required to make it. Next you make a .bat file and write the following code.

start javaw -jar NameOfJar.jar

Make sure that you put the file in the same directory as your jar. Now you should be able and click on the .bat and execute the program!

answered Aug 12 '13 at 23:30

2

  • created .bat file.. when i click it to run my jar, a cmd window opens and gets closed automatically

    Aug 23 '13 at 13:03

  • yeah, a batch file is really just a command prompt command, so the window will always open, no matter what you do. If you don't want the window then you will need to use a executable wrapper

    user2675678

    Aug 23 '13 at 13:55

1.Open Notepad & write

                @echo off  javac YOUR_JAVA_FILENAME.java  java YOUR_JAVA_FILENAME                              

2.Save-As executeJavaProgram.bat

Make sure that YOUR_JAVA_FILENAME.java resides with your batch file and java path is set in environment variable.

3 . Double click on batch file.

answered Jun 18 '13 at 6:03

2

  • Please make sure that the classname.java is in same folder where .bat file exist.

    Jun 18 '13 at 11:21

  • created .bat file.. when i click it to run my jar, a cmd window opens and gets closed automatically

    Aug 23 '13 at 13:04

Follow this tutorial to create a jar file of your eclipse project. After doing it create a batch file in the same folder where you exported the jar with the command: java -jar yourjar.jar

answered Jun 18 '13 at 6:01

2

  • created jar file with .java and classpath files. now when i double click jar file, it shows invalid or corrupted file error. are those 2 files enough to create jar OR should i include more files??

    Jun 18 '13 at 6:26

  • sis you follow the tutorial to generate the jar?

    Jun 18 '13 at 6:35

Create jar file using eclipse i.e right click on your project select export jar file then provide file name to store your jar file. In this file eclipse will keep all .class file only and in META-INF folder main class definition if your are creating executable jar file.

answered Jun 18 '13 at 6:03

2

  • created jar file with .java and classpath files. now when i double click jar file, it shows invalid or corrupted file error. are those 2 files enough to create jar OR should i include more files??

    Jun 18 '13 at 6:25

  • created .bat file.. when i click it to run my jar, a cmd window opens and gets closed automatically

    Aug 23 '13 at 13:04

Not the answer you're looking for? Browse other questions tagged java eclipse batch-file or ask your own question.

How To Create Batch File For Java Project

Source: https://stackoverflow.com/questions/17161422/run-java-project-built-in-eclipse-using-batch-file

Posted by: masonexprind1993.blogspot.com

0 Response to "How To Create Batch File For Java Project"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel