Given Main.java, data1.dat, data2.dat,
methods for creating a self-contained .jar with data file
0.use getResourceAsStream to get jar data at package root
InputStream is = Main.class.getResourceAsStream("/"+dataName);
1.add to all *.java source
package my.package;
2.compile with package start location
java -d . *.java
3.vi manifest.txt
#Class-Path: my.package
Main-Class: my.package.Main
4.produce jar file with data files
jar cvfm mypackage.jar manifest.txt my data1.dat data2.dat
5.run by
java -jar mypackage.jar
java -cp mypackage.jar my.package.Main
沒有留言:
張貼留言