Java maven和gwt的Log4j问题:org.apache.Log4j.XAppender对象不可分配
我有一个Maven GWT项目。我包括了Hibernate和HSQLDB作为持久层。运行单元测试很好,但当它尝试运行服务器组件时,日志记录不起作用,因此我对服务器端的错误视而不见。我遇到的错误有: [ERROR]log4j:错误“org.apache.log4j.RollingFileAppender”对象是 不属于“org.apache.log4j.Appender”变量。[错误] log4j:错误类“org.apache.log4j.Appender”是由 [错误]log4j:错误[sun.misc.Launcher]$AppClassLoader@baf1915]鉴于 类型为[ERROR]log4j的对象:错误 “org.apache.log4j.RollingFileAppender”由[WebApp]加载 类加载器=1312837549@4e404fad]. [错误]log4j:无法执行错误 实例化名为“file”的appender。[错误]log4j:错误A “org.apache.log4j.ConsoleAppender”对象未分配给 “org.apache.log4j.Appender”变量。[错误]log4j:类错误 “org.apache.log4j.Appender”由[ERROR]log4j:ERROR加载 [sun.misc.Launcher]$AppClassLoader@baf1915]而类型为 [ERROR]log4j:org.apache.log4j.ConsoleAppender加载错误 [WebAppClas sLoader=1312837549@4e404fad]. [错误]log4j:可能会发生错误 未实例化名为“stdout”的appender 通过谷歌搜索,我很确定这是因为log4j.jar有两个实例。 有没有一个好方法或最佳实践方法来解决这个问题?我从控制台以开发模式运行项目。 我的Pom.xml如下所示:Java maven和gwt的Log4j问题:org.apache.Log4j.XAppender对象不可分配,java,maven,gwt,log4j,Java,Maven,Gwt,Log4j,我有一个Maven GWT项目。我包括了Hibernate和HSQLDB作为持久层。运行单元测试很好,但当它尝试运行服务器组件时,日志记录不起作用,因此我对服务器端的错误视而不见。我遇到的错误有: [ERROR]log4j:错误“org.apache.log4j.RollingFileAppender”对象是 不属于“org.apache.log4j.Appender”变量。[错误] log4j:错误类“org.apache.log4j.Appender”是由 [错误]log4j:错误[sun.
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testproject</groupId>
<artifactId>trustme-mdm-gwtp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>GWTP Basic</name>
<description>Basic GWTP application</description>
<properties>
<!-- client -->
<gwt.version>2.6.0</gwt.version>
<gwtp.version>1.2.1</gwtp.version>
<gin.version>2.1.2</gin.version>
<!-- server -->
<guice.version>3.0</guice.version>
<!-- testing -->
<junit.version>4.7</junit.version>
<jukito.version>1.4</jukito.version>
<!-- maven -->
<gwt-maven-plugin.version>2.6.0</gwt-maven-plugin.version>
<maven-surefire-plugin.version>2.6</maven-surefire-plugin.version>
<maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>
<maven-resources-plugin.version>2.5</maven-resources-plugin.version>
<maven-processor-plugin.version>2.0.5</maven-processor-plugin.version>
<maven-build-helper-plugin.version>1.7</maven-build-helper-plugin.version>
<target.jdk>1.7</target.jdk>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
</properties>
<build>
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- JUnit Testing - skip *.GwtTest cases -->
<!-- 'mvn test' - runs the Jukito tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*GwtTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- GWT -->
<!-- 'mvn gwt:run' - runs development mode -->
<!-- 'mvn gwt:debug' - runs debug mode -->
<!-- 'mvn gwt:compile' - compiles gwt -->
<!-- 'mvn integration-test' - runs the gwt tests (*GwtTest.java) -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.version}</version>
<configuration>
<!-- With multiple tests use GwtTestSuite.java for speed -->
<includes>**/*GwtTest.java</includes>
<extraJvmArgs>-Xss1024K -Xmx1024M -XX:MaxPermSize=256M</extraJvmArgs>
<copyWebapp>true</copyWebapp>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<runTarget>Project.html</runTarget>
<modules>
<module>testproject.Project</module>
</modules>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Google Web Toolkit -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
</dependency>
<!-- GWT-Platform -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-all</artifactId>
<version>${gwtp.version}</version>
</dependency>
<!-- DI -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>com.google.gwt.inject</groupId>
<artifactId>gin</artifactId>
<version>${gin.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jukito</groupId>
<artifactId>jukito</artifactId>
<version>${jukito.version}</version>
<scope>test</scope>
</dependency>
<!-- Hibernate -->
<!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.5.Final</version>
</dependency>
<!-- hSQLDB -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
</dependency>
<!-- add slf4j interfaces to classpath -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
<!-- GWT-Log -->
<dependency>
<groupId>com.allen-sauer.gwt.log</groupId>
<artifactId>gwt-log</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</project>
4.0.0
测试项目
将log4j依赖范围更改为maven中提供的。检查是否存在多个记录器JAR。您可能面临GWT 2.6.0中的已知问题,该问题在DevMode中错误加载服务器端类:
尝试使用GWT2.6.1,看看这是否解决了问题
编辑:另外,清理依赖项的范围:您的WEB-INF/lib
中有gwt user
和servlet api
,它们一定不存在;您还有一堆GWT专用的客户端专用jar,它们也不应该在那里。谢谢您的帮助(尤其是Thomas)。
我在项目中使用的指南指出,log4j和slf4j在pom.xml中作为外部引用是必要的。
我只是简单地删除了它,它现在正在工作。然而,这教会了我,不结合服务器和客户机依赖关系确实让生活变得更简单 谢谢,我试过了,但还是有同样的错误:(您还需要清理依赖项的作用域。我甚至不知道spring和servlet api依赖项是如何进入lib文件夹的。如何避免这些jar出现在那里?pom.xml中的gwt配置来自正式的gwtproject页面。运行mvn dependency:tree
以了解依赖项的来源。我链接了依赖关系树在上面的帖子中。但我仍然不知道我在寻找什么。pom配置似乎在示例项目中非常常见。我知道复杂的项目往往会被分为服务器项目和客户端项目。但是不可能在一个项目中同时拥有这两个项目吗?我将范围更改为“提供”对于slf4j-log4j12包。这个组合包可能会有问题吗?我编辑了我的帖子,将JAR列表包含在我的lib文件夹中。使用eclipse并转到pom.xml,然后查看依赖关系层次结构并检查log4ja。对于我们来说,快速解决方法是将-Dlog4j.ignoreTCL=true传递给devMode
<!-- Google Web Toolkit -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>