java运行后运行另一个文件,如何从当前文件夹中的另一个Java程序运行存储在子目录中的Java程序...

I have big problem, please help me My situation is this, i have program RegAlloc.java, that uses several classes that is another packages P1 and P2. RegAlloc.java and these 2 packages are in a folder called Temp1. Temp is folder that contains Temp1 and Simplify.java, this folder also contains Pacjages named P! and P2 i needs to run RegAlloc from Simplify.java is there any solution? i am using the Linux platform, pls help me

try{

String s="RegAlloc.class";

String[] cmd = {"java", "-classpath=home/koha/pjt_new/Temp/Temp1/", s};

Process pro2 = Runtime.getRuntime().exec(cmd);

BufferedReader in = new BufferedReader(new nputStreamReader(pro2.getInputStream()));

String line = null;

System.out.println(in.readLine());

while ((line = in.readLine()) != null) {

text+=line;

text+="\n";

}

System.out.println(text);

} catch(Exception e) {

System.out.println("not Okey");

}

解决方案

Set the classpath variable and then run the program

Where I have the classes like as follows

COne class is in Package P1

CTwo Class is in Pakcage P2

Your Current folder is like F1 which contains COne.java and CTwo.java;

Compile the classes in the following manner.

javac -d . *.java

The above command will create two subdirectories in your current folder with the names P1 and P2 and the respective .class files will be pushed automatically

Set the Classpath environmental variable as :

set CLASSPATH=%CLASSPATH%;./P1;/P2;.

And Run Your Program like

java P1.COne

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值