Java CLI binaries seem to behave differently on Linux and Windows. It runs fine on Windows, but gives an error on Linux.
# reproduce on linux or windows
git clone https://github.com/jmnote/demo.git
cd demo
javac -d bin -cp "lib/*" src/*
java -cp "bin;lib/*" App
root@linux01:~:/demo# find | grep '.ja'
./src/App.java
./lib/gson-2.10.jar
root@linux01:~:/demo# cat src/App.java
import com.google.gson.Gson;
public class App {
public static void main(String[] args) {
Gson gson = new Gson();
System.out.println("hello");
System.out.println(gson);
}
}
PS C:\Users\user01> git clone https://github.com/jmnote/demo.git
Cloning into 'demo'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 10 (delta 1), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (10/10), 249.38 KiB | 22.67 MiB/s, done.
Resolving deltas: 100% (1/1), done.
PS C:\Users\user01> cd demo
PS C:\Users\user01\demo> javac -d bin -cp "lib/*" src/*
PS C:\Users\user01\demo> java -cp "bin;lib/*" App
hello
{serializeNulls:false,factories:[Factory...
root@linux01:~# git clone https://github.com/jmnote/demo.git
Cloning into 'demo'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 10 (delta 1), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
root@linux01:~# cd demo
root@linux01:~/demo# javac -d bin -cp "lib/*" src/*
root@linux01:~/demo# java -cp "bin;lib/*" App
Error: Could not find or load main class App
Caused by: java.lang.ClassNotFoundException: App
Why are the results different? Is there any way to run it without errors on Linux?