- 1 year ago
Building Jar using javapackager from command
To build a JAR file using javapackager
from the command line, you'll need to have JDK 8 or later installed on your system as javapackager
is part of the JavaFX packager tools, which were included with the JDK until Java 8. Starting from Java 9, JavaFX was removed from the JDK, and the JavaFX packager tools are now available separately.
Here are the steps to build a JAR file using javapackager
from the command line:
Make sure you have JDK 8 or later installed on your system.
Open a command prompt or terminal.
Navigate to the directory where your Java application's classes and resources are located.
Use the
javapackager
command with appropriate options to create the JAR file. The basic syntax is as follows:
bashjavapackager -createjar -outdir <output_directory> -outfile <output_jar_filename> -appclass <main_class_name> -srcdir <source_directory>
Replace the placeholders with the appropriate values:
<output_directory>
: The directory where you want the JAR file to be created.<output_jar_filename>
: The name of the JAR file (e.g.,MyApp.jar
).<main_class_name>
: The fully qualified name of the main class of your Java application (e.g.,com.example.MyAppMain
).<source_directory>
: The directory where your Java application's classes and resources are located.
Here's an example command for building a JAR file:
bashjavapackager -createjar -outdir ./out -outfile MyApp.jar -appclass com.example.MyAppMain -srcdir ./bin
After running the javapackager
command, you should find the generated JAR file in the specified output directory (./out
in the example above).
Please note that starting from Java 11, the JavaFX packager tools have been removed from the JDK entirely. If you're using Java 11 or later, you'll need to use alternative tools or build systems like Maven or Gradle to package your Java application into a JAR file.