-1

I have the assignment to create a project. I have programmed everything, but i was told to create a batch which executes my program on the console. My problem is to include the external jar, because i have nearly no experience with batch files.

The structure of my folders is

projectFolder{

srcFolder{...}

libFolder{lib1.jar; lib2.jar; ...}

resFolder{...}

binFolder{start.bat; Main.class; 

toolsFolder{Tool.class; ...} 

 ...}

I only know that it hat to include "java Main", but not what else, so would very appreciate your help how my batch file should look like :)

Edit:

I also got an example from an other project, but i understand nearly nothing of it :/

run.bat: @echo off

setlocal

set VM_MEMORY=1280m 

call runjava.bat %0 de.usu.skm.stats.Statistics %1 %2 %3 %4

endlocal

java.bat:

break off


if exist init.bat call init.bat


if not "%VM_MEMORY%" == "" goto SETVMOPTS

set VM_MEMORY=96m


:SETVMOPTS

rem USER_TIMEZONE must be set when you are using the ojdbc5 Oracle driver with 9i (and maybe 10i)

rem set USER_TIMEZONE=-Duser.timezone=CET

set USE_IPV4=-Djava.net.preferIPv4Stack=false

set VM_OPTS=-server -Xmx%VM_MEMORY% -Djava.security.policy=gatekeeper.policy 
-Djava.rmi.server.useCodebaseOnly=true -Djavax.net.ssl.keyStore=keystore 
-Djavax.net.ssl.keyStorePassword=gatekeeper -Djavax.net.ssl.trustStore=keystore 
-Djavax.net.ssl.trustStorePassword=gatekeeper 
-Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=20000 
-Dsun.net.inetaddr.ttl=10 %USE_IPV4% -Dzookeeper.preAllocSize=2048 
-Dzookeeper.authProvider.1=de.usu.ucp.UcpAuthenticationProvider -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true -Dorg.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false -DJAVA_HOME="%JAVA_HOME%" -Djava.io.tmpdir=../temp -Dorg.terracotta.quartz.skipUpdateCheck=true


:SETJAVA

if "%JAVA_HOME%" == "" goto NOJAVAHOME

rem echo Using JAVA_HOME %JAVA_HOME%

set JAVA_CMD="%JAVA_HOME%\bin\java.exe"

goto RUNJAVA



:NOJAVAHOME

echo WARNING: JAVA_HOME variable not set

set JAVA_CMD=java


:RUNJAVA

%JAVA_CMD% %VM_OPTS% -Dde.usu.toolname=%1 -Dde.usu.bootstrap.class=%2 
-Dde.usu.bootstrap.debug=%BOOTSTRAP_DEBUG% -cp bootstrap.jar  de.usu.bootstrap.Bootstrap %3 %4 %5 %6 %7 %8 %9


:END

break on

1 Answers1

0

Assuming that you know how to export your program as a runnable jar (Right click on the project - Export - java - Runnable JAR file), you could create a new file and change its extension to .bat

Let's say you have the .jar in the same location as the .bat file.

Write into the bat:

@echo off

java -jar "YOUR_JAR_NAME.jar"

YOUR_JAR_NAME must be replaced with your generated jar.

Start a command prompt (Win key + R and type cmd), go through the path of your .bat file and execute it by typing the name of your bat file and it's extension. It should start your .jar file.

Survivor
  • 674
  • 1
  • 7
  • 13
  • thank you for your answere, but is creating a jar at the beginning the only way? when i was told what the task is, it sounded like i should do it without using a jar except the already existing one i have to include :§ – Franzi Sollner Oct 14 '14 at 14:15
  • Well, you can run it without packing it as a jar by giving the path to the Main.class file or run the Main.java with javac command – Survivor Oct 14 '14 at 14:36
  • could you write a short example how that would look like? :) sorry, but in this area, i have really few experience :/ – Franzi Sollner Oct 14 '14 at 14:46