Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to create a batch file to run a Java application

Reply
Thread Tools

How to create a batch file to run a Java application

 
 
Cyril Dex
Guest
Posts: n/a
 
      10-13-2003
Hey guys

Does anyone know of where I can get information on how to get a batch
file to change directory into where class files are located and then
rum those java files - by double clicking on it.

e.g. set $PATH="c:/j2sdk1.4.2/bin" //where the java compiler is
located
cd c:/MyProgram
javac MyProgram.java
java MyProgram
 
Reply With Quote
 
 
 
 
Thomas Kellerer
Guest
Posts: n/a
 
      10-13-2003
Cyril Dex schrieb:

> Hey guys
>
> Does anyone know of where I can get information on how to get a batch
> file to change directory into where class files are located and then
> rum those java files - by double clicking on it.
>
> e.g. set $PATH="c:/j2sdk1.4.2/bin" //where the java compiler is
> located
> cd c:/MyProgram
> javac MyProgram.java
> java MyProgram


This is a Windows question not a Java question, but nevertheless:

cd /d c:\MyProgram

I can recommend cd /? as well!


 
Reply With Quote
 
 
 
 
Bryce (Work)
Guest
Posts: n/a
 
      10-13-2003
On 13 Oct 2003 08:21:38 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (Cyril Dex)
wrote:

>Hey guys
>
>Does anyone know of where I can get information on how to get a batch
>file to change directory into where class files are located and then
>rum those java files - by double clicking on it.
>
>e.g. set $PATH="c:/j2sdk1.4.2/bin" //where the java compiler is
>located
> cd c:/MyProgram
> javac MyProgram.java
> java MyProgram



1. YOu don't need to compile it each time you run it. Only when you've
changed something.

2.
set $PATH=$PATH;"c:java bin dir"


Although I generally don't do that. I'll create an environment
variable "JAVA_HOME", and set path to $JAVA_HOME/bin.

then my bat file is:

java -cp <my class path> <path to my program class>
 
Reply With Quote
 
Paul Lutus
Guest
Posts: n/a
 
      10-14-2003
Cyril Dex wrote:

> Hey guys
>
> Does anyone know of where I can get information on how to get a batch
> file to change directory into where class files are located and then
> rum those java files - by double clicking on it.
>
> e.g. set $PATH="c:/j2sdk1.4.2/bin" //where the java compiler is
> located
> cd c:/MyProgram
> javac MyProgram.java
> java MyProgram


You don't need to compile every time. And do it this way:

java -cp /MyProgram MyProgram

No need to change directories.

--
Paul Lutus
http://www.arachnoid.com

 
Reply With Quote
 
jeevana jeevana is offline
Junior Member
Join Date: May 2009
Posts: 1
 
      05-15-2009


@echo off
echo You Are going to creata Java Class
set /p Name=Enter your Class Name?:
echo Your class Name is %Name% & pause
echo To creat a Notepad
pause
notepad %Name%.java
set path=%PATH%;C:\Program Files\Java\jdk1.6.0_14\bin
pause
javac
echo Your java Path succsussfully set.
javac %Name%.java
pause
echo Successfully Compiled
java %Name%
pause

1)open a notpad
2)copy and past this code and save this file as <name.bat>
ex: test.bat
3)Double Click tha batch file.
3)put your java codes into the notepad and save it as <your_java_class_name.java>
N.B.:- save this java file same folder that your batch file exists.
 
Reply With Quote
 
jobinvs jobinvs is offline
Junior Member
Join Date: Apr 2010
Posts: 2
 
      04-21-2010
Hope this post will be useful for someone in search of this:
Batch Files.
1st Batch File:"RunJava.bat"
@echo off
cd /d %~dp0
call "D:\JavaPrograms\source\source.bat"
Pause
echo "Program Executed"
2nd Batch File:"sourece.bat"
@echo off
cd /d %~dp0
ECHO.
echo ************************************************** ************
dir D:\JavaPrograms\source\*.java
ECHO.
echo ************************************************** ************
ECHO.
set /p Name=Enter one Java file name from above list for execution:
javac -d ..\Classes %Name%.java
call D:\JavaPrograms\classes\Classes.bat %1 %Name%
echo "Successfully Executed"

3rd Batch File:"Classes.bat"
@echo off
cd /d %~dp0
echo Name=%Name%
echo Output of the Program
echo ---------------------
java %Name%
call "C:\Documents and Settings\Administrator\Desktop\RunJava.bat"
Working Help
In My system:
1. The RunJava.bat is place in the desktop. I write java programs in notepad or Editplus and save programs in "D:\JavaPrograms\source"
2. The "source.bat" is placed in "D:\JavaPrograms\source".
3.The compiled classes file are stored in "D:\JavaPrograms\Classes".
4.This is done with the help of "javac -d ..\Classes %Name%.java" <- compile and store the class file in ..\Classes folder
5.The "source.bat" calls "Classes.bat"
6.The "Classes.bat" in placed in"D:\JavaPrograms\Classes."
7.The "Classes.bat" runs the java program.

Batch File: RunJava.bat
1.Place this file any where in your computer.
2.This batch file is executed in the current directory through
cd /d %~dp0
call "D:\JavaPrograms\source\source.bat"
This is the place where the java source files are stored also this is the place for source.bat.




Batch File: source.bat
1.This batch file compiles the .java file.
2.dir D:\JavaPrograms\source\*.java: lists all the java programs in the source folder
3.set /p Name=Enter one Java file name from above list for execution:
The above statement accepts the program name like "HelloWorld" without .java extension

which needs to be compiled. Do not specify the name of the program as "HelloWorld.java".
4.javac -d ..\Classes %Name%.java: Compiles the "HelloWorld" java file and places the compiled class file under the Classes folder.
5.call D:\JavaPrograms\classes\Classes.bat %1 %Name% : Calls the Classes.bat file which is residing in Classes folder.







Batch File: Classes.bat
1.Classes.bat resides inside Classes folder.
2.This batch file runs the java program "java %Name%";
3.call "C:\Documents and Settings\Administrator\Desktop\RunJava.bat": Call the RunJava.bat file.
 

Last edited by jobinvs; 04-21-2010 at 08:17 AM..
Reply With Quote
 
jobinvs jobinvs is offline
Junior Member
Join Date: Apr 2010
Posts: 2
 
      04-21-2010
Quote:
Originally Posted by Cyril Dex
Hey guys

Does anyone know of where I can get information on how to get a batch
file to change directory into where class files are located and then
rum those java files - by double clicking on it.

e.g. set $PATH="c:/j2sdk1.4.2/bin" //where the java compiler is
located
cd c:/MyProgram
javac MyProgram.java
java MyProgram
Hope this post will be useful for someone in search of this:
Batch Files.
1st Batch File:"RunJava.bat"

@echo off
cd /d %~dp0
call "D:\JavaPrograms\source\source.bat"
Pause
echo "Program Executed"

2nd Batch File:"sourece.bat"

@echo off
cd /d %~dp0
ECHO.
echo ************************************************** ************
dir D:\JavaPrograms\source\*.java
ECHO.
echo ************************************************** ************
ECHO.
set /p Name=Enter one Java file name from above list for execution:
javac -d ..\Classes %Name%.java
call D:\JavaPrograms\classes\Classes.bat %1 %Name%
echo "Successfully Executed"


3rd Batch File:"Classes.bat"

@echo off
cd /d %~dp0
echo Name=%Name%
echo Output of the Program
echo ---------------------
java %Name%
call "C:\Documents and Settings\Administrator\Desktop\RunJava.bat"

Working Help
In My system:
1. The RunJava.bat is place in the desktop. I write java programs in notepad or Editplus and save programs in "D:\JavaPrograms\source"
2. The "source.bat" is placed in "D:\JavaPrograms\source".
3.The compiled classes file are stored in "D:\JavaPrograms\Classes".
4.This is done with the help of "javac -d ..\Classes %Name%.java" <- compile and store the class file in ..\Classes folder
5.The "source.bat" calls "Classes.bat"
6.The "Classes.bat" in placed in"D:\JavaPrograms\Classes."
7.The "Classes.bat" runs the java program.

Batch File: RunJava.bat
1.Place this file any where in your computer.
2.This batch file is executed in the current directory through
cd /d %~dp0
call "D:\JavaPrograms\source\source.bat"
This is the place where the java source files are stored also this is the place for source.bat.




Batch File: source.bat
1.This batch file compiles the .java file.
2.dir D:\JavaPrograms\source\*.java: lists all the java programs in the source folder
3.set /p Name=Enter one Java file name from above list for execution:
The above statement accepts the program name like "HelloWorld" without .java extension

which needs to be compiled. Do not specify the name of the program as "HelloWorld.java".
4.javac -d ..\Classes %Name%.java: Compiles the "HelloWorld" java file and places the compiled class file under the Classes folder.
5.call D:\JavaPrograms\classes\Classes.bat %1 %Name% : Calls the Classes.bat file which is residing in Classes folder.







Batch File: Classes.bat
1.Classes.bat resides inside Classes folder.
2.This batch file runs the java program "java %Name%";
3.call "C:\Documents and Settings\Administrator\Desktop\RunJava.bat": Call the RunJava.bat file.
 
Reply With Quote
 
sankalp.sawant59 sankalp.sawant59 is offline
Junior Member
Join Date: Mar 2013
Posts: 1
 
      03-10-2013
thanx...i want to do similar stuff for sql quries...wat i have to do..post code for that...thanx in advance..
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a batch file for Java Console Application? Mozart Java 7 06-16-2011 07:41 AM
run batch file in client side viki ASP .Net 8 08-20-2010 07:27 PM
TO run an Application from Batch file viki ASP .Net Security 4 10-27-2004 04:56 PM
Use process class to run batch file in web server =?Utf-8?B?WjBnUw==?= ASP .Net 4 02-18-2004 11:26 PM
How to run a batch file. Mike John ASP .Net 1 07-23-2003 01:29 PM



Advertisments