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

外部文件在程序中设置成相对当前工程路径,执行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   

原文地址:https://www.cnblogs.com/ontway/p/7429772.html