0

I'm starting Fuseki server through cmd line interface command. Following way;

    ![My CMD working code]

enter image description here

    D:
    cd jena-fuseki-1.0.1
    fuseki-server --update --mem /ds

How can I run above code through java class without opening any CMD line interface? So many stackoverflow answers provide below code.

     Process child = Runtime.getRuntime().exec(command);

But I didn't get how should apply my above things to here.

Updated question;

public class Test {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    String[] command = { "fuseki-server", "--update", "--mem", "/ds" };
    File directory = new File("D:\\jena-fuseki-1.0.1");
    ProcessBuilder pb = new ProcessBuilder(command);
    pb.directory(directory);

    try {
        pb.start();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

} Error message : "java.io.IOException: Cannot run program "fuseki-server" (in directory "D:\jena-fuseki-1.0.1"): CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(Unknown Source)"

enter image description here

Maduri
  • 249
  • 1
  • 5
  • 19

2 Answers2

0

You need to put the extension (.exe, .bat, ...) to the fuseki-server command file (the shell does it for you but here you are giving the filename).

You also need to use pb.start() to actually start the process.

Teudimundo
  • 2,610
  • 20
  • 28
  • I tried "fuseki-server.bat", also. But same error gave me. What did you mean pb.start() ? Error message no clear me. – Maduri Nov 19 '14 at 11:04
  • 1
    what @Teudimundo mean is you need to put the full filename for your `fuseki-server` command. For windows, executable file normally ended with .exe, .com, .bat. Try run `dir fuseki-server*.*` at command prompt to get the full filename. – Joey Chong Nov 19 '14 at 11:20
  • @JoeyChong I added fuseki-server.bat. But same error gave me. Is there any otherway to run this server like Tomcat server run when application start? (Like adding to class path) – Maduri Nov 19 '14 at 17:46
  • 2
    Try change `fuseki-server.bat` to `D:\\jena-fuseki-1.0.1\\fuseki-server.bat`. – Joey Chong Nov 20 '14 at 02:44
  • @JoeyChong Your genius. After 3 wk you solved my problem. Thank you so much. Have a nice day :). – Maduri Nov 20 '14 at 06:03
0

Fuseki is a java servlet webapp. See https://github.com/apache/jena/tree/master/jena-fuseki2/src/main/webapp. You can take the .war file and put it in tomcat or jetty or whatever for yourself, you don't need to use any special launcher.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • I already added Apache Tomcat in to class path. Is it possible to add two servers? My server folder contain both Tomcat and jena-fuseki-1.0.1. How can I add jena-fuseki-1.0.1 into class path? Isn't it a problem to add to servers? – Maduri Nov 19 '14 at 11:23
  • I added screen shot of my server hierarchy of eclipse J2EE project. Where should I put Fuseki server inside Tomcat server? – Maduri Nov 19 '14 at 11:44