Skip to content

Instantly share code, notes, and snippets.

@martiner
Created January 6, 2013 12:23
Show Gist options
  • Save martiner/4466801 to your computer and use it in GitHub Desktop.
Save martiner/4466801 to your computer and use it in GitHub Desktop.
Class load dependency
public class Depend {
public Depend() {
System.out.println("Hello World!");
}
}
import java.util.Scanner;
public class Main {
public static void main(String... args) throws Exception {
try {
Class.forName("FOO").newInstance();
} catch (Exception ignore) {}
System.out.print("Delete the target directory then hit ENTER: ");
new Scanner(System.in).nextLine();
Class.forName("Depend").newInstance();
}
}
#!/bin/bash
TARGET=target
MAINJAR=$TARGET/main.jar
DEPENDJAR=$TARGET/depend.jar
mkdir -p $TARGET
javac -d $TARGET src/Main.java src/Depend.java
jar cf $MAINJAR -C $TARGET Main.class
jar cf $DEPENDJAR -C $TARGET Depend.class
java -cp $MAINJAR:$DEPENDJAR Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment