Compiling java for compatibility and JAR for other platforms

Build it with JAR and make it backward compatible.   

Better way to explain this is to instead show a hello world example of this.


Folder and file structure:

manifest.txt
src
src/hello.java
src/libraries
src/libraries/a.java
src/libraries/b.java
build
build/classes


Using --release 8 means build it for version 8.  Latest version supports backward compatibility. 

javac --release 8 -sourcepath src -d build/classes src/*.java
javac --release 8 -sourcepath src -d build/classes src/libraries/*.java
jar cfmv build/jar/hello.jar manifest.txt -C build/classes .
java -jar build/jar/hello.jar


manifest.txt

Main-Class: hello

src/hello.java

import libraries.*;

public class hello {
public static void main(String[] args){
System.out.println("Hello World main");
System.out.println(a.message());
b.message("hello from b");
}
}

src/libraries/a.java

package libraries;

public class a {
public static String message(){
String s = "";
        s = "Hello from a";
return s;
}
}

src/libraries/b.java

package libraries;

public class b {
public static void message(String args){
System.out.println(args);
}
}






Popular Posts