kreetrapper has asked for the wisdom of the Perl Monks concerning the following question:

Dear fellow monks,

I am currently trying to integrate some Java into a perl program and I seem to be stuck. This is the relevant part of my code:

BEGIN { $ENV{CLASSPATH} .= ":log4j.properties:log4j-1.2.14.jar:myclass.jar" +; $ENV{EXTRA_JAVA_ARGS} = "-Dlog4j.debug"; } use Inline Java => 'STUDY', STUDY => ['mypackage.myclass','org.apache.log4j.Logger' +], AUTOSTUDY => 1;

As you can see, the Java code I am trying to integrate uses log4j and that seems to be the problem, because when I run this code I get the following warnings:

log4j:WARN No appenders could be found for logger (xxx.yyy.DBConnection).
log4j:WARN Please initialize the log4j system properly.

After googling this message, I found this, where it says:

The reason why you see this message is that your log4j configuration file(i.e. log4j.xml or log4j.properties) is NOT found in the classpath.

But I have a log4j.properties in the same folder as my script and the jars I use. As you can see from the code snippet above, i tried to explicitly add the properties file to the classpath. I also tried to switch on log4j debugging via EXTRA_JAVA_ARGS, but nothing has helped me to get rid of the warnings.

I use perl 5.8.7 on SuSE Linux 10.0 and Inline::Java 0.52.

Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Using log4j via Inline::Java
by Anonymous Monk on May 18, 2009 at 07:16 UTC
    is log4j.properties a JAR? You should add current directory (. or /f/f/o/o/bar)

      Oh, my God!

      That worked! And it was so simple.

      Thank you very much!

Re: Using log4j via Inline::Java
by dHarry (Abbot) on May 18, 2009 at 07:56 UTC

    In my experience you'll always have to fiddle to make log4j work;) I can think of several things you could try:

    • Add the location of the properties file explicitly to the CLASSPATH. You might want to try to add the full path.
    • Add the properties file to the jar file.
    • Fiddle with the $ENV{EXTRA_JAVA_ARGS} part. I think the argument you provide is not correct/complete, i.e. the "-Dlog4j.debug" part. I would expect something like "-Dlog4j.configuration=dir_where_to_find_config_file/log4j.properties".

    Sanity check: I assume you have established that log4j actually works if you run the java app.?

    HTH
    Harry