开发者

Jruby log4j integration

开发者 https://www.devze.com 2023-01-20 02:55 出处:网络
I am currently working on integrating Java application General Architecture For Text Engineering (GATE) with a Rails application using JRuby architecture. When we worked on integrating JRuby with log4

I am currently working on integrating Java application General Architecture For Text Engineering (GATE) with a Rails application using JRuby architecture. When we worked on integrating JRuby with log4j, I am getting following error:

0 [main] DEBUG Main.class  - Hello world
gate/Gate.java:80:in `<clinit>': java.lang.NoClassDefFoundError: org/apache/log4

j/Logger (NativeExcepti开发者_Python百科on) from gateapp/Main.java:86:in `main' from test.rb:12

test.rb is the name of ruby program.

I tried importing all the log4j apache libraries, and included the class file in the test.rb file.

When I run the Java program alone its running fine. But when I generate the jar file and include them in Ruby file (test.rb) , I am getting this error

java.lang.NoClassDefFoundError: org/apache/log4j/Logger (NativeException) problem is occuring. How to deal with this problem ?


You need to make sure the log4j JAR file is in your classpath. One way to do this is to set the CLASSPATH variable in your environment. Another way would be to call require in your ruby code like

  require "/some/path/MyStuff.jar" 


Here is my config to set it up with couchbase Java SDK

include Java

def setup_log4j
  java::lang.System.setProperty("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.Log4JLogger")

  fa = Java::OrgApacheLog4j::FileAppender.new();
  fa.setName("FileLogger");

  fa.setFile("./log/#{Rails.env}.log");
  fa.setLayout(Java::OrgApacheLog4j::PatternLayout.new("%d %-5p [%c{1}] %m%n"));
  fa.setThreshold(Java::OrgApacheLog4j::Level::INFO);
  fa.setAppend(true);
  fa.activateOptions();
  Java::OrgApacheLog4j::Logger.getRootLogger().addAppender(fa)
end

Just beware that I required the lo4j.jar file earlier.
Worth to mention that there is project named log4jruby.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号