• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

JUnit Initialization Problem Related to Struts, org.apache.commons.log, and Log4J

In Websphere, I am trying to run JUnit Test on a Struts 1.1 application.  When I ran the JUnit Test, I encounter the following exception:

java.lang.NoSuchMethodError: org.apache.log4j.Category: method log(Ljava/lang/String;Lorg/apache/log4j/Level;Ljava/lang/Object;Ljava/lang/Throwable;)V not found
at org.apache.commons.logging.impl.Log4JCategory.info(Log4JCategoryLog.java:109
...

The last line of our system's code that caused the exception is the following:
log.info(...)

Log is created with the following line:
private final Log log = LogFactory.getLog(getClass());
This line of code appears in an abstract class.  The LogFactory class here is org.apache.commons.logging.LogFactory.  

Note that this code works perfectly fine when the application is started normally through Websphere, so I know this is an initialization problem.  I have tried using MockStrutsTestCase and fiddling a little bit, but that did not work.  Any help is appreciated.  Thanks.

- Tom
0
tsewen
Asked:
tsewen
  • 7
  • 6
1 Solution
 
objectsCommented:
Looks like you eaither don't have the log4j jar available in the classpath when you run it as a unit test, or you have a different verwsion of the jar
0
 
tsewenAuthor Commented:
Would you know how I may check the log4j jar available in the classpath when I run the JUnit test?  I am running JUnit in Websphere.
0
 
objectsCommented:
first two places to check would be the ext directory of tyhe jre you are using to run it, and your CLASSPATH environment variable
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tsewenAuthor Commented:
I found that neither the CLASSPATH environment variable's path nor the ext directory of the JRE I am using in Websphere has log4j-1.2.8.jar or its directory.  After putting log4j-1.2.8.jar into the ext directory and rebooting the machine, I still have the same problem.  There seems to be some classloader issue that stems from how J2EE's classloaders are set up.  And I am looking up some articles now.
0
 
objectsCommented:
> nor the ext directory of the JRE I am using in Websphere has log4j-1.2.8.jar

Its the one you're using to run your test that you should be looking at.
Websphere has nothing to do with it (as its running fine)
0
 
tsewenAuthor Commented:
I am running JUnit as part of Websphere (likely as a plugin), so I thought that was the JRE to look at.  If that's the wrong JRE, would you know how to find the right JRE?  Thanks.
0
 
objectsCommented:
Sorry, wasn't aware of that. How exactly do you do that (I'm not a WS person)
0
 
tsewenAuthor Commented:
Websphere seems to come with JUnit as a plugin.  Websphere is essentially Eclipse with lots of IBM plugins, I believe, so if you know about Eclipse, you know something about Websphere.
0
 
objectsCommented:
have a look at your build path then, and see if junit is specified in there
0
 
tsewenAuthor Commented:
JUnit has its own options pane, and I am sure it's running, since you see the JUnit Runner when you run a JUnit Testcase as a JUnit test.  The suspicious part though is how the J2EE class loading mechanism differs from the regular class loading in a regular J2SE application, as I have found a number of articles through Google.  Here are some Google searches I did, but I had not spent much time trying potential solutions yet.

http://www.google.com/search?hl=en&q=websphere+junit+j2ee
http://www.google.com/search?hl=en&lr=&safe=active&q=j2ee+junit+log4j
0
 
objectsCommented:
sorry, that was a typo, I meant log4j
0
 
tsewenAuthor Commented:
I am looking into setting up CactusStrutsTestCase to see if I can solve this problem.

Tom
0
 
tsewenAuthor Commented:
Hi objects,

Since your answer has not solved my question but certainly pointed me in the right direction, I am giving you a B grade for the answer.  Thanks for all your help.

- Tom
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now