如何从当前文件夹中的另一个Java程序运行存储在子目录中的Java程序 [英] how to run a java program stored in sub directory from another java program in the current folder

查看:298
本文介绍了如何从当前文件夹中的另一个Java程序运行存储在子目录中的Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有个大问题,请帮我.我的情况是,我有RegAlloc.java程序,该程序使用几个类,它们是另一个程序包P1和P2. RegAlloc.java和这两个软件包位于名为Temp1的文件夹中. Temp是包含Temp1和Simplify.java的文件夹,此文件夹还包含名为P!的Pacjages.和P2我需要从Simplify.java运行RegAlloc.有什么解决方案吗?我正在使用Linux平台,请帮助我

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");
}

推荐答案

设置classpath变量,然后运行程序

Set the classpath variable and then run the program

我有如下类的课程

  1. COne类在程序包P1中
  2. CTwo类位于Pakcage P2中
  3. 您当前的文件夹就像F1一样,其中包含COne.java和CTwo.java;

以以下方式编译类.

javac -d . *.java

以上命令将在当前文件夹中创建两个子目录,名称分别为P1和P2,并且各自的.class文件将被自动推送

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

将Classpath环境变量设置为:

Set the Classpath environmental variable as :

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

然后像这样运行您的程序

And Run Your Program like

java P1.COne

这篇关于如何从当前文件夹中的另一个Java程序运行存储在子目录中的Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆