launching a java application in background
Dear all,
I need to launch a java proccess as a daemon, in background.
It would be like the following:
java bin/aplicacion.jar
In interactive mode works fine. We have tried to launch it in background using nohup.
If I send everything (all redirections <> ) to /dev/null it works, but I do not get the logs
We have tried:
java bin/aplication.jar < /dev/null > output.log 2>&1 &
But I get in the output file carachters like "->"
Any time of getting those logs?
I hope I have explained myself fine
Regards
Miguel
Quoted 21 lines · El Miércoles, 2 de Febrero de 2005 16:24, escribió:
Dear all,
I need to launch a java proccess as a daemon, in background.
It would be like the following:
java bin/aplicacion.jar
In interactive mode works fine. We have tried to launch it in background using nohup.
If I send everything (all redirections <> ) to
/dev/nullit works, but I do not get the logsWe have tried:
java bin/aplication.jar <
/dev/null> output.log 2>&1 &But I get in the output file carachters like "->"
Quoted 7 lines
Any time of getting those logs?
I hope I have explained myself fine
Regards
Miguel
To deal with this I change on my Java applications, the System.out.* By calls to other kind of OUT, then you can make a simple pointer by default from System.out, System.err, or substitute this by file output, then you can pass an extra argumento to your software to log by default on a file, and use the same object (could be static code).
Java have a mechanism to put a thread on a background, in daemon mode, you should find more about. Here is an example how I use an objet to have properties, like out, and err, you can establish a socket, or open a file for writing and you can set the new output calling setOut or setErr.
------------------
package com.compunauta.util;
/**
* Title: RUNTimeManager
* Description: OUT, ERR, PROPERTIES, handler for threads.
* for html parser.
* Copyright: Copyright (c) 2001
* Company: www.compunauta.com
* @author Gustavo Guillermo Pérez
* @version 1.0
*/
import java.io.PrintStream;
import java.io.BufferedReader;
import java.util.Properties;
import java.util.Hashtable;
public class RunTimeManager {
public int EXIT_CODE=0;
public boolean BIGFAILURE=false;
public boolean DEBUG=false;
public boolean CHILDREN_MODE=false;
public boolean STOP=false;
public PrintStream out=System.out;
public PrintStream err=System.err;
public static String WORK_DIR="./";
public Properties p=(Properties)null;
public static Properties sp=new Properties(); public static Hashtable h=new Hashtable(10); public BufferedReader in=new BufferedReader(new java.io.InputStreamReader(System.in));
public RunTimeManager(){}
public RunTimeManager(boolean debug){this.DEBUG=debug;} public RunTimeManager(boolean debug,boolean standalone)
{this.DEBUG=debug;this.CHILDREN_MODE=!standalone;}
public void setChildren(boolean value){CHILDREN_MODE=value;}
public void setStandAlone(boolean value){CHILDREN_MODE=!value;}
public void setChildren(){CHILDREN_MODE=true;}
public void setStandAlone(){CHILDREN_MODE=false;}
public boolean VERVOSE=true;
public boolean exit(int EXIT_CODE){
this.EXIT_CODE=EXIT_CODE;
this.STOP=true;
if (EXIT_CODE!=0){BIGFAILURE=true;}
if (CHILDREN_MODE) return true;
else System.exit(EXIT_CODE);
return false;
}//end exit
public void reset(){
this.BIGFAILURE=false;
this.EXIT_CODE=0;
this.STOP=false;
}//end reset
public void setOut(PrintStream out){
this.out=out;
}//end out
public void setErr(PrintStream err){
this.err=err;
}//end err
public void setIn(BufferedReader in){
this.in=in;
}//end err
public void setPropertiesFromHash(String Key){
Object ob=h.get(Key);
Properties p;
if (ob==null) {p=new Properties();h.put(Key,p);}
else {p=(Properties)ob;}
}//end setpropfromhash
public void setDebugOn(){this.DEBUG=true;}
public void setDebugOff(){this.DEBUG=false;}public void setProperty(String Key, String Value){
if (this.p==null){sp.setProperty(Key,Value); return;} this.p.setProperty(Key,Value);
}//end setproperty
public String getProperty(String Key, String Default){
if (this.p==null){return sp.getProperty(Key,Default);}
else {String ob=p.getProperty(Key,Default);
if (ob==null){
return sp.getProperty(Key,Default);
}else return ob;}
}//end getProperty
public String getProperty(String Key){
return getProperty(Key,null);
}//end getProp
public static String getEnvironOs(){
//REQManipulation env=new REQManipulation(System.getProperty("os.name"));
String env=System.getProperty("os.name");
// System.out.println(System.getProperties());
if (env.toLowerCase().indexOf("linux")!=-1) return "l";
if (env.toLowerCase().indexOf("windows")!=-1) return "w";
if (env.toLowerCase().indexOf("sol")!=-1) return "s";
return "w";
}//end getEnvironOs
}//end class
Signature · 7 lines
Gustavo Guillermo Pérez Compunauta uLinux www.ulinux.tk - To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html