I have to create a batch file such that it should call a specific java file present in eclipse.
Asked
Active
Viewed 222 times
1
-
It should call or Run ? – Ninad Pingale Aug 01 '14 at 12:27
-
in batch file it should call specified file present in src folder, after that i need to write a java program which automatically trigger batch file thanks in advance – user3427658 Aug 01 '14 at 12:28
-
Why dont you start the "java file" from Java? – Stefan Aug 01 '14 at 12:34
1 Answers
0
Suppose, your java file is in path:
D:/WorkDir/Java/Filename.java
Then your bat file (say abc.bat
) should be,
d:
cd WorkDir/Java
java Filename
Below is an example, where you have commands to set java class path and include additional jar files and pass arguments to Filename.java
set classpath=%classpath%;c:\MY APPS\lib\log4j.jar;
d:
cd WorkDir/Java
java Filename arg1 arg2 arg3 etc
To call the bat file from java, you need to use runtime.exec as below and in this link.
Runtime rn=Runtime.getRuntime();
Process pr=rn.exec(path);
-
In the batch file you can use `pushd %~dp0` to change dir to current directory. Otherwise it will be Eclipse's working directory. – Stefan Aug 01 '14 at 12:36
-
@Stefan: Bat files are necessary for scheduler type of applications. We use in our environment. For normal cases, as you recommend, we can start the java file from java itself. – ngrashia Aug 01 '14 at 12:39
-
@user3427658: That is just a sample. Say you want to add log4j.jar to your class path, then you can add such jars in your classpath with the command mentioned. – ngrashia Aug 01 '14 at 12:40
-
acutally i received src folder frm my mentor, its der in my document folder.i tried to create a batch file like this – user3427658 Aug 01 '14 at 12:43
-
-
pushd %DIRNAME%.. pushd %DIRNAME%.. pushd %DIRNAME%.. set DCM_HOME=%CD% set PATH=%PATH%; set CW_CLASSPATH="%DCM_HOME%Users\sjuttu\Documents\My Received Files\src\lib\diffutils-1.2.1.jar;%DCM_HOME%Users\sjuttu\Documents\My Received Files\src\lib\log4j-1.2.16.jar;%DCM_HOME%Users\sjuttu\Documents\My Received Files\src\lib\postgresql-9.3-1101.jdbc41.jar;%DCM_HOME%Users\sjuttu\Documents\My Received Files\src\lib\super-csv-2.2.0.jar;%DCM_HOME%Users\sjuttu\Documents\My Received Files\src\lib\util.jar – user3427658 Aug 01 '14 at 12:45
-
set CW_CMD="%DCM_HOME%Program Files\Java\jre7\bin\java" -cp %CW_CLASSPATH% com.brocade.comparator.DatabaseComparator cmd /c start "Java" %CW_CMD% pause but i dnt knw wether this code is crt or not, "cmd /c start "java" %CW_CMD%" purpose is what. thanks in advance – user3427658 Aug 01 '14 at 12:47