User Tools

Site Tools


doc:appunti:prog:java_compile_jar_command_line

This is an old revision of the document!


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;

Download the included libraries

It is advisable to create a directory which will contains all the libraries (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

FIXME $CLASSPATH

find . -name '*.class' | xargs -r rm
find . -name '*.java' > sources.txt
javac --class-path $CLASSPATH @sources.txt

Pack the Jar archive

FIXME $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.1636369244.txt.gz · Last modified: 2021/11/08 12:00 by niccolo