1. 程式人生 > >Java打包可執行jar包 包含外部文件

Java打包可執行jar包 包含外部文件

star bsp end clas adl pro readline 令行 inpu

外部文件在程序中設置成相對當前工程路徑,執行jar包時,將外部文件放在和jar包平級的目錄。

 1 public class Main {
 2 
 3   
 4     public static void main(String[] args) throws IOException, InterruptedException {
 5 
 6         String a=args[0];
 7 
 8         String b=args[1];
 9 
10         String c=args[2];
11 
12         String[] cmd=new String[3];
13 14 cmd[0]="python"; 15 16 cmd[1]="testpython.py"; 17 18 System.out.println(a+" "+b+" "+c); 19 20 System.out.println("start"); 21 22 Process proc = Runtime.getRuntime().exec(cmd); 23 24 BufferedReader in=new BufferedReader(new InputStreamReader(proc.getInputStream()));
25 26 String line; 27 28 while ((line=in.readLine())!=null){ 29 30 System.out.println(line); 31 32 } 33 34 in.close(); 35 36 proc.waitFor(); 37 38 System.out.println("end"); 39 40 } 41 42 }

在命令行執行可執行jar命令 java -jar hello.jar

Java打包可執行jar包 包含外部文件