1

I have a java class "Test.java" which contains certain code.

public class Test {

public static void main(String[] args) throws Exception {
    testMount();
}

public static void testMount() throws Exception {
    System.out.println(System.getProperty("os.name"));
    //Windows
    String volumeToMount = "\\\\?\\Volume{****-****-******-********}\\";
    String mountPoint = "C:\\temp\\";

    mountFileSystem("", "", volumeToMount, mountPoint); //This carries out the operation        
}
}

I have already compiled the code in Linux Operating System. I want to run the compiled code through a batch script ( .bat file). How do i do that? What is the syntax for that? If i have to add some external jars, where and how do I insert them in the syntax within the .bat file?

3
  • you should include the external jars in compilation (you should have an option to compile external libraries in eclipse/netbeans) when you are exporting the project into jar Commented Sep 9, 2011 at 8:53
  • You say that you compiled it under Linux but .bat files are Windows batch files. Do you want hints for Windows or Linux? Commented Sep 9, 2011 at 9:13
  • I've compiled them in Linux.But i want to run those compiled files in windows. Commented Sep 9, 2011 at 9:21

2 Answers 2

3

here is an example of bat file for executing a java code from the jar with external jars:

@echo off

if "X%JAVA_HOME%" == "X" goto setjavahome
goto setup

:setjavahome
rem #### MODIFY ##########
set JAVA_HOME=c:\program files\javasoft\jre\1.2
rem #######################

:setup
set JNDI_LIB=lib\ldap.jar;lib\jndi.jar;lib\providerutil.jar;lib\ldapbp.jar
set JSSE_LIB=lib\jsse.jar;lib\jnet.jar;lib\jcert.jar

set COMMON=.;%JNDI_LIB%;%JSSE_LIB%
set EXEC=browser.jar lbe.ui.BrowserApp

set CMD="%JAVA_HOME%\bin\java" -cp %COMMON%;%EXEC%

echo %CMD%
%CMD%
Sign up to request clarification or add additional context in comments.

Comments

0

.bat is for Windows; try to compile your Java codes in Windows to EXE (with your external libraries, as suggested by galchen), and add your EXE name along with relative / absolute path to the batch file.

For example, the output EXE is named as test.exe, the batch file should contain:

START C:\PATH\TO\YOUR\EXE\test.exe

Advantage of compiling to EXE is mainly for performance.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.