x0070704
x0070704
2013-08-19 10:37
浏览 254
已采纳

maven整合ssh3启动出现LogManager NoClassDefFoundError错误

maven整合ssh3启动出现错误java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager
上网搜了一下,都说没加入log4j的包,但我明明加入进去了啊
slf4j-api, slf4j-log4j12, commons-logging, log4j 都加了,还是报错
下面是我的错误信息和pom.xml


Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager
at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:209)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:221)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newConfiguration(LocalSessionFactoryBean.java:813)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:549)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 52 more





<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cms</groupId>
<artifactId>cms</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>gdcms Maven Webapp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.0.2.RELEASE</spring.version>
<slf4j.version>1.5.6</slf4j.version>
<aspectj.version>1.6.12</aspectj.version>
<struts2.version>2.3.15.1</struts2.version>
<hibernate.version>3.3.2.GA</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<dependency>
<groupId>ojdbc</groupId>
<artifactId>ojdbc</artifactId>
<version>14</version>
</dependency>
<!-- struts2的核心包,其依赖包会自动下载 -->

<dependency>

<groupId>org.apache.struts</groupId>

<artifactId>struts2-core</artifactId>

<version>${struts2.version}</version>

</dependency>
<dependency>

<groupId>org.apache.struts</groupId>

<artifactId>struts2-json-plugin</artifactId>

<version>${struts2.version}</version>

</dependency>
<!-- struts2与spring的整合插件 -->

<dependency>

<groupId>org.apache.struts</groupId>

<artifactId>struts2-spring-plugin</artifactId>

<version>${struts2.version}</version>

</dependency>

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<!-- spring的核心包,其他依赖包会自动下载 -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>${spring.version}</version>

</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- 使用spring的aop,aop要依赖aspectjweaver -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-aop</artifactId>

<version>${spring.version}</version>

</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>

<groupId>org.aspectj</groupId>

<artifactId>aspectjweaver</artifactId>

<version>${aspectj.version}</version>

</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.3</version>
</dependency>
<!-- 使用这里的工具类对字符串进行MD5加密 -->

<dependency>

<groupId>commons-codec</groupId>

<artifactId>commons-codec</artifactId>

<version>1.7</version>

</dependency>

<!-- j2ee web spec -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- hibernate的核心包,使用hibernate4时报错就改用了hibernate3 -->

<dependency>

<groupId>org.hibernate</groupId>

<artifactId>hibernate-core</artifactId>

<version>${hibernate.version}</version>

</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jmx</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- spring整合hibernate需要添加上spring的orm的jar包, 由于spring-orm是

依赖于spring-jdbc的, 所以这里即使不配spring-jdbc,maven也会帮我们

下载下来这些依赖

-->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

<version>${spring.version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-orm</artifactId>

<version>${spring.version}</version>

</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.3</version>
</dependency>

    &lt;dependency&gt;
        &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
        &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
        &lt;version&gt;${slf4j.version}&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;

    &lt;!-- hibernate-core依赖于slf4j-api,而slf4j-api需要一个实现类,这个  
            实现类jar可以是slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar,   
        slf4j-jdk14.jar ,logback-classic.jar其中之一 --&gt;  
    &lt;dependency&gt;  
        &lt;groupId&gt;org.slf4j&lt;/groupId&gt;  
        &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;  
        &lt;version&gt;${slf4j.version}&lt;/version&gt;     
    &lt;/dependency&gt; 
   &lt;dependency&gt;
        &lt;groupId&gt;commons-logging&lt;/groupId&gt;
        &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
        &lt;version&gt;1.1.1&lt;/version&gt;
    &lt;/dependency&gt;
      &lt;!-- log4j日志记录 --&gt; 
      &lt;dependency&gt;  
        &lt;groupId&gt;log4j&lt;/groupId&gt;  
        &lt;artifactId&gt;log4j&lt;/artifactId&gt;  
        &lt;version&gt;1.2.16&lt;/version&gt; 
        &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;!-- json --&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;net.sf.json-lib&lt;/groupId&gt;
        &lt;artifactId&gt;json-lib&lt;/artifactId&gt;
        &lt;version&gt;2.4&lt;/version&gt;
        &lt;classifier&gt;jdk15&lt;/classifier&gt;
    &lt;/dependency&gt;
    &lt;!-- junit4用来进行单元测试 --&gt; 
  &lt;dependency&gt;
  &lt;groupId&gt;junit&lt;/groupId&gt;
  &lt;artifactId&gt;junit&lt;/artifactId&gt;
  &lt;version&gt;3.8.2&lt;/version&gt;
  &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt; 

</dependencies>
<build>
<finalName>gdcms</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.1.2.v20100523</version>
<configuration>
<webAppConfig>
<contextPath>/cms</contextPath>
</webAppConfig>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8088</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<!--scanIntervalSeconds>1</scanIntervalSeconds -->
</configuration>
</plugin>
<plugin>
<!-- Must use java 1.5 or higher for annotations -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • liuyongpo
    liuyongpo 2013-08-19 13:53
    已采纳

    这个错误不可能会是没有log4j的jar包导致的,这个提示是初始化LogManager的时候出了问题,不知道你那边有没有更细节的堆栈信息?只依靠目前的信息,只能推测是log4j的版本可能存在冲突,我看了下slf4j-log4j12-1.5.6依赖的log4j应该是1.2.14,你此处使用的是1.2.16,不知道是不是这个引起的

    点赞 评论
  • zyn010101
    zyn010101 2013-08-19 10:41

    看看project引入的jar,是否log4j引入多个了

    点赞 评论
  • jinandmei
    jinbingchuan 2013-08-19 10:42

    你可以把你仓库里的logjar给删除掉重新下载一次,或者你浏览你的工程里面看下你依赖的log文件是不是在里面能够找到

    点赞 评论
  • cnfh110
    时之砂cap 2013-08-19 18:24

    slf4j.version的版本和log4j版本需要统一

    点赞 评论

相关推荐