### Batch to create Jar

This is an example of a batch file for creating a Jar for a JavaFX Java project.
Two example options:
Option 1 with direct Package and Class
Option 2 with with Parameter set in the batch
Option 1 with direct Package and Class
@Echo Off
REM JavaFX Java Development - Creating executable Jar for Project HelloJavaFX (Package hellojavafx, Class HelloJavaFX)
REM Folder Structure:
REM Source: c:\Daten\java\JavaFX\Apps\HelloJavaFX\
REM Class: c:\Daten\java\JavaFX\Apps\HelloJavaFX\hellojavafx
REM Jar: c:\Daten\java\JavaFX\Apps\HelloJavaFX\jar
REM
REM This batch is run from Folder c:\Daten\java\JavaFX\Apps\HelloJavaFX
REM
@Echo JavaFX Example Project HelloJavaFX
REM
@Echo Set Project Source Folder
cd c:\Daten\java\JavaFX\Apps\HelloJavaFX\
dir /b *.java
REM
@Echo Compile Java Class in Folder hellojavafx
"c:\Program Files (x86)\Java\jdk8\bin\javac.exe" -d . HelloJavaFX.java
dir /b hellojavafx\*.class
REM
@Echo Create JAR in Folder jar
"c:\Program Files (x86)\Java\jdk8\bin\javapackager.exe" -createjar -appclass hellojavafx.HelloJavaFX -srcdir . -outdir jar -outfile hellojavafx.jar -v
dir /b jar\*.jar
REM
@Echo Run JAR located in folder jar from the Project folder
"c:\Program Files (x86)\Java\jdk8\bin\javaw.exe" -jar jar/hellojavafx.jar
REM
@Echo Done ...
Pause
Option 2 with Parameter set in the batch
@Echo Off
REM JavaFX Java Development - Creating executable Jar for Project
REM Set p for Package name (lowercase) and c for Classname (Capital)
Set p=hellojavafx
Set c=HelloJavaFX
@Echo JavaFX Java Development - Creating executable Jar for Project %c% (Package %p%, Class %c%)
REM Folder Structure:
REM Source: c:\Daten\java\JavaFX\Apps\%c%\
REM Class: c:\Daten\java\JavaFX\Apps\%c%\%p%
REM Jar: c:\Daten\java\JavaFX\Apps\%c%\jar
REM
REM This batch is run from Folder c:\Daten\java\JavaFX\Apps\%c%
REM
@Echo JavaFX Example Project %c%
REM
@Echo Set Project Source Folder
cd c:\Daten\java\JavaFX\Apps\%c%\
dir /b *.java
REM
@Echo Compile Java Class in Folder %p%
"c:\Program Files (x86)\Java\jdk8\bin\javac.exe" -d . %c%.java
dir /b %p%\*.class
REM
@Echo Create JAR in Folder jar
"c:\Program Files (x86)\Java\jdk8\bin\javapackager.exe" -createjar -appclass %p%.%c% -srcdir . -outdir jar -outfile %p%.jar -v
dir /b jar\*.jar
REM
@Echo Run JAR located in folder jar from the Project folder
"c:\Program Files (x86)\Java\jdk8\bin\javaw.exe" -jar jar/%p%.jar
REM
@Echo Done ...
Pause

Changed: , Category: JavaFX Java Development, File: T6C207M1512.htm, ID: 1512