Java – run a jar file in PHP and write a file

When executing the jar file, I have the following problems in PHP I use the following command:

exec("java -jar JavaProject4.jar";

JavaProject4. Jar creates a TXT file in the path given in the Java code

When I run a project in NetBeans, a TXT file is created However, when I execute jar in PHP, I don't get any errors, but I can't get the file

Here is the Java code I use to write files:

public static void main(String[] args) throws InterruptedException,FileNotFoundException,IOException {

    Main a = new Main();
    List<Double> l1 = new ArrayList<Double>();

    l1 = a.compute_features();
    //System.out.println(l1);

    FileWriter fstream1 = new FileWriter("C:/wamp/www/test/out.txt");
    BufferedWriter out1 = new BufferedWriter(fstream1);
    out1.write(l1.toString());
    out1.newLine();
    out1.close();
}

I use PHP 5.2 4 Wamp server and the latest java version

Thank you.

Editor: the problem has been solved. I moved the main java files in NetBeans to the default package and fixed the wrong path. Now everything works as expected

Thank you

Solution

When you run it in PHP, how do you do it? Are you using the PHP cli (command line interface), or are you running it through an Apache module (CGI or otherwise)? The reason I ask is that the problem you encounter may be related to the user executing the script If you are using cli, you will run as a Windows user, but if you run it through Apache, it will run like a user running Apache Therefore, you may need to provide permissions for Apache users of the directory to write to

Hello, Ralph

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>