properties file in a JAR

Hello, I have the following class:

import org.apache.log4j.Logger;

import org.apache.log4j.PropertyConfigurator;

publicclass Ejemplo3{

static Logger logger = Logger.getLogger(Ejemplo3.class.getName());

publicstaticvoid main(String[] args){

PropertyConfigurator.configure(args[0]);

logger.info("Entrando en la aplicaci髇.");

for(int i=1; i<10; i++){}

logger.info("Saliendo de la aplicaci髇.");

}

}

And this is my properties file (log4j.properties):

# Coloca el nivel del root logger en DEBUG y adiciona un solo appender que es A1.

log4j.rootLogger=DEBUG, A1

# A1 es configurado para utilizar ConsoleAppender.

log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 utiliza PatternLayout.

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

I don't have problems executing this like:

java Ejemplo3 log4j.properties

Now, I would like to put this in a JAR, but I don't know where to put the properties file and what to write in the MANIFEST.MF to send the properties file like argument.

Thanks beforehand!!

_

Excuse my english :(

Message was edited by:

aprendizdejava

[1857 byte] By [aprendizdejavaa] at [2007-11-27 10:10:07]
# 1

You want to place the log4j.properties inside the .jar? You can read the log4j.properties inside the jar and give the Properties to log4j like this:

String propertiesFile= "pathInJar/log4j.properties";

InputStream in = getClassLoader().getResourceAsStream(propertiesFile);

if (in != null)

{

Properties props = new java.util.Properties();

props.load(in);

PropertyConfigurator.configure(props);

}

else

{

//PropertiesFile not found! (Handle the problem)

}

rakanea at 2007-7-13 0:46:51 > top of Java-index,Desktop,Deploying...