问题描述
我有一个Maven GWT项目。我将Hibernate和HSQLDB作为持久层。运行单元测试很好,但是当它尝试运行服务器组件时,日志记录不起作用,所以我对服务器端的错误一无所知。我遇到的错误是:
lockquote
[错误] log4j:错误org.apache.log4j.RollingFileAppender对象是
不能分配给org.apache.log4j.Appender变量。 [错误]
log4j:错误类org.apache.log4j.Appender由
加载[错误] log4j:错误[sun.misc.Launcher$AppClassLoader@baf1915]而
[ERROR]类型的对象log4j:ERROR
org.apache.log4j.RollingFileAppender由[WebApp
ClassLoader = 1312837549 @ 4e404fad]加载。 [错误] log4j:错误
无法实例化名为file的appender。 [错误] log4j:错误
org.apache.log4j.ConsoleAppender对象不能分配给
org.apache.log4j.Appender变量。 [错误] log4j:错误类
org.apache.log4j.Appender由[错误]加载log4j:错误
[sun.misc.Launcher$AppClassLoader@baf1915]而类型
[错误] log4j:ERRORorg.apache.log4j.ConsoleAppender被
加载[WebAppClas sLoader = 1312837549 @ 4e404fad]。 [错误] log4j:错误可能
没有实例化名为stdout的appender。
从Google搜索中我确定它是因为有两个log4j.jar实例存在。
是否有解决此问题的好方法或最佳实践方法?我从控制台运行开发模式的项目。
My Pom.xml看起来像这样:
<?xml version =1.0encoding =UTF- 8\" >?;
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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>
<名称> GWTP基本< /名称>
< description>基本GWTP应用程序< / description>
<属性>
<! - 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>
< junit.version> 4.7< /junit.version>
< jukito.version> 1.4< /jukito.version>
< 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>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-surefire-plugin< / artifactId>
< version> $ {maven-surefire-plugin.version}< / version>
<配置>
<包括>
< include> ** / * Test.java< / include>
< / includes>
< exclude> ** / * GwtTest.java< / exclude>
< /不包括>
< / configuration>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 2.3.2< / version>
<配置>
< source> 1.7< / source>
< target> 1.7< / target>
< / configuration>
< / plugin>
< plugin>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> gwt-maven-plugin< / artifactId>
<版本> $ {gwt.version}< / version>
<配置>
< includes> ** / * GwtTest.java< / includes>
< extraJvmArgs> -Xss1024K -Xmx1024M -XX:MaxPermSize = 256M< / extraJvmArgs>
< copyWebapp> true< / copyWebapp>
< hostedWebapp> $ {webappDirectory}< / hostedWebapp>
< runTarget> Project.html< / runTarget>
<模块>
< module> testproject.Project< / module>
< / modules>
< / configuration>
<执行次数>
<执行>
<目标>
< goal>编译< / goal>
< goal> test< / goal>
< /目标>
< /执行>
< /执行次数>
< / plugin>
< / plugins>
< / build>
<依赖关系>
<! - Google Web Toolkit - >
< dependency>
< groupId> com.google.gwt< / groupId>
< artifactId> gwt-user< / artifactId>
<版本> $ {gwt.version}< / version>
< /依赖关系>
< dependency>
< groupId> com.gwt平台< / groupId>
< artifactId> gwtp-all< / artifactId>
< version> $ {gwtp.version}< / version>
< /依赖关系>
< dependency>
< groupId> com.google.inject< / groupId>
< artifactId> guice< / artifactId>
< version> $ {guice.version}< / version>
< /依赖关系>
< dependency>
< groupId> com.google.inject.extensions< / groupId>
< artifactId> guice-servlet< / artifactId>
< version> $ {guice.version}< / version>
< /依赖关系>
< dependency>
< groupId> com.google.inject.extensions< / groupId>
< artifactId> guice-assistedinject< / artifactId>
< version> $ {guice.version}< / version>
< /依赖关系>
< dependency>
< groupId> com.google.gwt.inject< / groupId>
< artifactId> gin< / artifactId>
< version> $ {gin.version}< / version>
< /依赖关系>
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> $ {junit.version}< / version>
< scope> test< / scope>
< /依赖关系>
< dependency>
< groupId> org.jukito< / groupId>
< artifactId> jukito< / artifactId>
< version> $ {jukito.version}< / version>
< scope> test< / scope>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-entitymanager< / artifactId>
< version> 4.3.5.Final< / version>
< /依赖关系>
< dependency>
< groupId> org.hsqldb< / groupId>
< artifactId> hsqldb< / artifactId>
< version> 2.3.2< / version>
< /依赖关系>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-log4j12< / artifactId>
< version> 1.7.7< / version>
< /依赖关系>
<! - GWT-Log - >
< dependency>
< groupId> com.allen-sauer.gwt.log< / groupId>
< artifactId> gwt-log< / artifactId>
< version> 3.3.0< / version>
< /依赖关系>
< /依赖关系>
< / project>
当我看看\target ... \lib文件夹时,这些是被部署的罐子:
我将pom.xml更改为:
<! - Google Web Toolkit - >
< dependency>
< groupId> com.google.gwt< / groupId>
< artifactId> gwt-servlet< / artifactId>
<版本> $ {gwt.version}< / version>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> com.google.gwt< / groupId>
< artifactId> gwt-user< / artifactId>
<版本> $ {gwt.version}< / version>
< scope>提供< / scope>
< /依赖关系>
但仍然没有成功...
我插入了依赖关系树的屏幕截图。我的声望不允许粘贴图像。它存储在这里:
我的项目中使用的指南指出,log4j和slf4j作为pom.xml中的外部引用是必要的。
我只是删除它,它现在正在工作。然而,这教会了我,通过不结合服务器和客户端的依赖关系,它确实使生活更简单。
I have a Maven GWT project. I included Hibernate and HSQLDB as persistence layer. Running the unit tests is fine, but when it try to run the server component, logging does not work and so I am blind to the errors on the server side. The errors I encouter are:
From googling I am pretty sure it is because two instances of the log4j.jar are present.Is there a good way or best practice way to solve this issue? I run the project in development mode from the console.My Pom.xml looks like this:
<?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>
When I take a look at the \target...\lib folder, these are the jars that are deployed:
I changed the pom.xml to this:
<!-- 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>
But still no success...
I inserted a screenshot of the dependency tree. My reputation does not allow to paste images. It is stored here:
Thanks for the help (especially Thomas). The guide i used for my project stated log4j and slf4j would be necessary as external references in the pom.xml.
I simply removed it and it is working now. This has taught me however, that it really makes life simpler by not combining server and client dependencies.
这篇关于使用maven和gwt的log4j问题:org.apache.log4j.XAppender对象不可分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!