• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

running a batch file by making jar file  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there is any way out to create a jar file which will make run a batch file inside it.

the need come when i have completed my snake and ladder game project and then i created a batch file to run snake and ladder game which is on applet and run it through batch using applet viewer and it runs successfully.
then i thought that is there is any way out to run a batch file directly when we execute a jar file so that look and feel good and easy for the user to run a jar file which in turn run your batch file and for those who doesn't knows about batch file it will be easier for them.

i will be thankful to you people.
 
Sheriff
Posts: 12199
199
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual approach is something quite the opposite:

Create an archive (zip, tar, tar.gz) file that includes a batch/shell script and the JAR file. You will normally have a README file as well that contains the setup and "How to run this program" instructions.

The user extracts the contents from the archive, reads the README and follows the instructions, which is usually to run the batch/shell script after some initial environment setup, if necessary. The batch/script file takes care of all the details of running the Java program.
 
Ranch Hand
Posts: 201
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand you correctly, you want to run a jarfile that in turn kicks off a batch file that does something.

To do this add the batch file to your jarfile. Then create a Process that runs the batchfile.
 
Marshal
Posts: 59756
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Processes are too difficult for “beginning”, so I shall move this discussion.
 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Processes are too difficult for “beginning”, so I shall move this discussion.



That's fine by me; however, I have seen that there seems little differentiation between General and Beginning; in fact I've often times read more difficult questions on the Beginner forum than on the General one ... even thought I know it ought not to be that way. ;)
 
Aman Tandon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much mr. Bill
sir i need some more help... you say firstly i will make a batch fil that run my game using appletviewer game.html
then i make a jar file and put just this batch file in it. then what i have to do..i am not getting that..
and when we make the executable jar file then we have to make manifest file..so how to make entry of batch file in it.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You say your program is an applet. Applets are designed to be run in web pages, not from a command line. The appletviewer program is intended to be used for testing, not running your program in a production environment.
If you want to run your program as a normal application, then create a normal application, not an applet, and put it into an executable jar. The user can then just click on the jar to run it.
 
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bill Johnston wrote:To do this add the batch file to your jarfile. Then create a Process that runs the batchfile.


Is it actually possible? Batch file is interpreted by cmd.exe in Windows, and I didn't succeed trying to force cmd.exe run a bat file inside a zip.

(As Adrian mentioned, this still would not be a good idea in this case, I just got interested into running batch files from jars in general. Also, I assume "Windows" when I see "batch file", as other OSes usually call them "scripts".)
 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Martin Vajsar wrote:

Bill Johnston wrote:To do this add the batch file to your jarfile. Then create a Process that runs the batchfile.


Is it actually possible? Batch file is interpreted by cmd.exe in Windows, and I didn't succeed trying to force cmd.exe run a bat file inside a zip.

(As Adrian mentioned, this still would not be a good idea in this case, I just got interested into running batch files from jars in general. Also, I assume "Windows" when I see "batch file", as other OSes usually call them "scripts".)



Worked when I tried it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!