I’m making a web application that, at a certain point, starts a new thread and this thread executes a jar file from command line.
The command line jar works fine when called from outside the application, but when i call it from the thread the relative path becomes C:\eclipse\ (i’m running the application from Eclipse) instead of the directory it’s stored in, which messes up with its configuration since it looks for files in the wrong place.
The jar creates a log file, whenever i try to call it i have this line written in the log: “10/04/2012 17:09:03 – java.io.FileNotFoundException: C:\eclipse\descriptors\analysis_engine\AggregateAE.xml”
The jar is not inside C:\eclipse. When i call it from prompt i have no problems, but when it’s called from a new spawned thread i have this error. I’ve tried it on a production environment and i have the same problem (this time the base path is the server’s one)
Considering that i can’t modify all the paths, what could be a solution to this problem?
EDIT: this is the thread class that calls the jar
public class UimaThread extends Thread {
private int mode=0;
private String path;
public UimaThread(int mode, String path){
this.mode=mode;
this.path=path;
}
public void run() {
Runtime run = Runtime.getRuntime();
try {
Properties config = ConfigLoader.getConfig();
String uimaPath=config.getProperty("uimaPath")+ControlPanelUtils.getDelimiter(config.getProperty("uimaPath"));
//uimaPath is the absolute path to the jar file, mode and path are just arguments passed to the jar
run.exec("java -jar "+uimaPath+"uimachainfull.jar "+mode+" "+path);
}
}
The code running this is:
public void startUima() throws IOException, ServletException {
Properties config = ConfigLoader.getConfig();
UimaThread uimaThread = new UimaThread(2, config.getProperty("docPath"));
uimaThread.start();
}
I need this to be executed asyncronously and outside the server, i’ve asked how to do that here in stackoverflow and i’ve been told to do so: Calling an application from a web server asynchronously
I’ve discovered how to do it, instead of using exec(String command) i had to use exec(String command, String[] envp, File dir) and the last argument (dir) is the working directory that can be passed as new argument