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