سؤال

Packaging a log4j configuration file in a NetBeans Platform application apparently requires some thinking through. This is what I tried...

I put log4j.xml in src/main/resources/my/package/log4j.xml of some_netbeans_module. The package is a public module package (i.e. classes from this package are used from other packages). I rebuilt the module and confirmed that the file does, in fact, get packaged into the module.

In my classes I get an instance of the logger the way I always do:

static final Logger log = Logger.getLogger(ThisClass.class);

Every NetBeans Platform application has a my_app.conf file which makes it possible to set certain properties. This is where I set log4j.conf:

log4j.configuration="/my/package/log4j.xml"

Now, when I run the application, I see the following output:

[INFO] /home/me/my_app/application/target/my_app/bin/../etc/my_app.conf: 5:
log4j.configuration=/my/package/log4j.xml: not found

What is wrong with the above configuration?

هل كانت مفيدة؟

المحلول

In the my_app.conf file if you append the log4j.configuration property to the default_options property, like so:

default_options="...<other options> -J-Dlog4j.configuration=my/package/log4j.xml"

then this option will get passed to the JVM. Notice that the log4j property has -J-D appended to it. The -J is used by NetBeans to delineate JVM properties and the -D is used by the JVM to delineate a system property.

Also you can/should drop the quotes and the initial / as the quotes are not necessary and NetBeans will complain if you have the initial /

The other way to do this, and the way that I prefer since it doesn't require editing the .conf file, is to put the log4j.xml file into the default package. If you have other requirements that prevents you from doing this then remember that you must put the log4j.configuration property in the app's platform.properties file while your in dev mode and running the app inside of the IDE. Like so:

run.args.extra=-J-Dlog4j.configuration=my/package/log4j.xml

Edit: For questions regarding NetBeans Platform you might have better luck posting to the NetBeans Platform Users forum.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top