0

I have deployed my Rest API on Tomcat 7.

It is deployed at following path :

/var/lib/tomcat7/webapps/myproject

And I have a Jar file which is kept at this location :

/home/user/executor/datacollector.jar

I am getting problem while running this jar from my application. It is not running when called using this code.

My code for running it is :

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "/home/user/executor/datacollector.jar");


Process p = pb.start();
ResultStream resultStream = new ResultStream(p.getInputStream());
Thread thread = new Thread(resultStream , "resultStream");
thread.start();


public class ResultStream implements Runnable {

private static Logger logger = Logger.getLogger("ResultStream");

private BufferedReader reader;

public ResultStream(InputStream is) {
    this.reader = new BufferedReader(new InputStreamReader(is));
}

public void run() {
    try {
        String line = reader.readLine();

        logger.info("line - "+line);

        while (line != null) {
           logger.info(line);
            line = reader.readLine();
        }
        reader.close();
    } catch (IOException e) {
        logger.error("IOException in executing jar",e);
       // e.printStackTrace();
    }
    catch (Exception e) {
        logger.error("Error in executing jar",e);
       // e.printStackTrace();
    }
}

}

Is there anything wrong in path, because It is outside webapps folder of Tomcat.

Please point out my mistake.

Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
  • Do you get any exception while calling the RESTFul service? Any reason for not adding the jar in the class path? – Samy Jan 22 '14 at 11:20
  • No..Not getting any exception. And Jar is accessible from other 2 applications.So kept outside. – Ninad Pingale Jan 22 '14 at 11:26

1 Answers1

0

If your tomcat instance is being run by another user, for example a separate "tomcat" user, then it may not have permission to access the files in your [user's] home directory.

Try moving the jar (and reference path in your java code) to a 'lib' folder, in your tomcat directory.

Sodman
  • 659
  • 5
  • 21
  • Thanks it worked after moving it to tomcat.But still I want to keep my jar files outside tomcat.Even after assigning same user for both tomcat and home directory, I get same error. – Ninad Pingale Jan 23 '14 at 06:40
  • You may need to change the permissions on the folder/file of your jar. You probably want to change it to 755, so that you can read/write/execute it, and all other users can read/execute it. See the top answer of http://stackoverflow.com/questions/16756995/what-folders-can-my-tomcat-application-write-to-on-ubuntu-server – Sodman Jan 23 '14 at 13:52