Last active
September 21, 2020 09:21
-
-
Save nimatrueway/baecf702d04f2b2f26385a6e4da65212 to your computer and use it in GitHub Desktop.
Java classpath/classloaders binary conflict test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
rm -rf dir1 dir2; | |
mkdir -p dir1/pkg; | |
cat >File.java <<EOL | |
package pkg; | |
public class File { | |
public static void main(String[] args) { | |
System.out.println("dir1/File"); | |
} | |
} | |
EOL | |
javac File.java; | |
mv File.class ./dir1/pkg; | |
mkdir -p dir2/pkg; | |
cat >File.java <<EOL | |
package pkg; | |
public class File { | |
public static void main(String[] args) { | |
System.out.println("dir2/File"); | |
} | |
} | |
EOL | |
javac File.java; | |
mv File.class ./dir2/pkg; | |
OUTPUT_DIR1_DIR2=$(java -cp dir1:dir2 pkg.File) | |
OUTPUT_DIR2_DIR1=$(java -cp dir2:dir1 pkg.File) | |
echo "" | |
echo " RESULT OF 'java -cp dir1:dir2 pkg.File' =>" | |
echo " $OUTPUT_DIR1_DIR2" | |
echo "" | |
echo " RESULT OF 'java -cp dir2:dir1 pkg.File' =>" | |
echo " $OUTPUT_DIR2_DIR1" | |
echo "" | |
rm File.java; | |
rm -rf dir1 dir2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to prove the point mentioned by AlexR in:
https://stackoverflow.com/a/9757698/1556045
default URLClassLoader picks up class-file content from the first classpath entry
Read more in depth about classloaders in:
https://www.cs.rit.edu/~ark/lectures/cl/05_02_00.html