Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am having some issues with Java (OpenJDK Java 7 Runtime) on Ubuntu 12.04, and just want to make sure I have my CLASSPATH and JAVA_HOME variables set correctly.

CLASSPATH=".:/usr/local/sbin:/home/king/Documents/bin/java/jar/*:/home/king/Documents/bin/java/jar/log4j.xml:/opt/fop/build/fop.jar"
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"

Is my JAVA_HOME varibale set right here? I am wondering if it should be set to

JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/jre"

instead?

My main issue I am having is with log4j

log4j:WARN No appenders could be found for logger (org.apache.fop.util.ContentHandlerFactoryRegistry).
log4j:WARN Please initialize the log4j system properly.

I have the file "log4j.xml" in a location on the classpath, so I am confused about the problem.

share|improve this question
    
JAVA_HOME is the path to the installation directory. Usually /usr/lib/jvm/java-7-openjdk-i386 should do it. The classpath usually lists only directory paths - not individual jars. –  sridhara Aug 20 '12 at 21:39
    
Neither JAVA_HOME nor CLASSPATH are "required" to run Java apps. By convention, shell scripts invoking Java apps may use JAVA_HOME to point to one JVM when there's more than one installed, or it's installed in a non-standard directory not in the PATH. If not programming (ie: using multiple JVM's + mvn/ant etc), don't set it; just use (g)alternatives to put Java in your default PATH. If you do set JAVA_HOME, the executable is always $JAVA_HOME/bin/java. The var CLASSPATH is used by the JVM, but don't set it (very error-prone). Instead use the cmd line options for javac/java/ant/mvn. –  michael_n Sep 29 '12 at 8:38
    
@sridhara a classpath usually lists actual jars. Directories are for "exploded" (unarchived) jars or other unarchived resources (such as log4j config.) (A directory of jars can also be specified: see askubuntu.com/questions/186693/… ) That being said, setting a global CLASSPATH is bad/wrong. Rather, there should be one classpath per individual application: thus use command-line options (e.g, java -cp dir1:dir2/foo.jar:dir3). (Note: depending on the tool, the cmd line option might be -classpath or just -cp). –  michael_n Sep 29 '12 at 8:46
    
yes you're right @michael_n . not sure what I was on about. –  sridhara Sep 29 '12 at 13:20

1 Answer 1

up vote 1 down vote accepted

If I understand correctly the problem is not with java. The problem is in your log4j.xml file.

Inside the class org.apache.fop.util.ContentHandlerFactoryRegistry it would have a : logger.error("Error Message/Exception") or logger.debug . . .

something along these lines and it is trying to write it to your logger that you have set up.

Essentially, you want to have something like

<logger name="org.apache.fop">
  <level value="info"/> 
</logger>

in your log file that will pick up logging messages from that class.

if you have multiple appenders then add

<appender-ref ref="appenderName" />

underneath the level tag.

share|improve this answer
    
If an output log file was created, then the log4 config was found and this answer is correct. If no log file was created, the log4j config file was likely not found at all. Normally a log4j config should have a default appender including everything under "org.*" , "com.*", etc., to avoid errors like this. There's also a chance that this message was printed before logging was completely configured, and later log messages actually did make it to the log file. If this is your own app, then using slf4j instead of (or as a wrapper for) log4j will make your logging and your life much simpler. –  michael_n Sep 29 '12 at 8:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.