doc:appunti:prog:java_compile_jar_command_line
This is an old revision of the document!
−Table of Contents
How to compile a jar from the command line
On a Debian GNU/Linux version 11.0 Bullseye it is required to install the default-jdk package, to have the javac compiler.
Reqired libraries
A Java project generally includes several libraries; you can find lines like this into the .java sources:
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
If you don't download and install the proper .jar archives, you will get errors like the following when executing the javac compiler:
./org/vmax/amba/cfg/FirmwareConfig.java:3: error: package com.fasterxml.jackson.annotation does not exist import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Download the included libraries
It is advisable to create a directory which will contains all the libraries (downloaded as jar archives) required by your project, that directory should be placed at the root level of your Java project.
└─ java-project/ ├─ lib/ │ ├─ apache-commons-net.jar │ ├─ commons-math3-3.0.jar │ ├─ ... │ └─ slf4j.jar └─ org/ └─ vmax/ ├─ amba/ │ ├─ bitrate/ │ ├─ ... │ ├─ AppMain.java │ ├─ ... │ └─ Utils.java └─ midrive/
Compile the Java code
$CLASSPATH
find . -name '*.class' | xargs -r rm find . -name '*.java' > sources.txt javac --class-path $CLASSPATH @sources.txt
Pack the Jar archive
$CLASSES
echo 'Main-Class: org.vmax.amba.AppMain' > manifest.txt echo "Class-Path: $CLASSES" >> manifest.txt jar --create --verbose \ --file='firmware-editor-tool.jar' \ --main-class='org.vmax.amba.AppMain' \ --manifest='manifest.txt' \ $(find . -type f -name '*.class')
doc/appunti/prog/java_compile_jar_command_line.1636369438.txt.gz · Last modified: 2021/11/08 12:03 by niccolo