我有一个Maven GWT项目。 我包括Hibernate和HSQLDB作为持久层。 运行单元测试是好的,但是当它试图运行的服务器组件,日志记录不工作,所以我盲目地在服务器端错误。 我encouter的错误是:
[ERROR]的log4j:ERROR A “org.apache.log4j.RollingFileAppender进行” 对象不assig nable于 “org.apache.log4j.Appender” 变量。 [ERROR]的log4j:ERROR类 “org.apache.log4j.Appender” 被加载[ERROR]的log4j:ERROR [sun.misc.Launcher$AppClassLoader@baf1915]而键入[ERROR]的log4j的对象:ERROR“有机apache.log4j.RollingFileAppender”是由[Web应用程序类加载器= 1312837549 @ 4e404fad]加载。 [错误] log4j的:错误无法实例附加器命名为“文件”。 [ERROR]的log4j:ERROR A “org.apache.log4j.ConsoleAppender” 对象不是可分配e的 “org.apache.log4j.Appender” 变量。 [ERROR]的log4j:ERROR类 “org.apache.log4j.Appender” 被加载[ERROR]的log4j:ERROR [sun.misc.Launcher$AppClassLoader@baf1915]而键入[ERROR]的log4j的对象:ERROR“有机apache.log4j.ConsoleAppender”是由[WebAppClas sLoader = 1312837549 @ 4e404fad]加载。 [错误] log4j的:错误无法实例附加器命名为“标准输出”。
从谷歌上搜索我敢肯定这是因为log4j.jar的两个实例都存在。 有没有好的办法或最佳实践的方式来解决这个问题? 我在运行从控制台发展方式的项目。 我的pom.xml看起来是这样的:
<?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>
当我看看的\目标... \ lib文件夹,这些都是部署在罐子:
ANTLR-2.7.7.jar aopalliance-1.0.jar commons-collections提供-3.2.1.jar公地郎2.4.jar共享记录-1.1.1.jar的dom4j-1.6.1.jar杜松子酒2.1.2。罐子番石榴16.0.1.jar番石榴GWT-16.0.1.jar吉斯 - 3.0.jar吉斯 - assistedinject-3.0.jar吉斯 - servlet的3.0.jar GWT-杰克逊0.4.0.jar GWT-LOG-3.3 .0.jar gwtp-全1.2.1.jar gwtp的客户端 - 共1.2.1.jar gwtp - 履带1.2.1.jar gwtp分派,共客户1.2.1.jar gwtp-dispatch-共共享1.2.1.jar gwtp分派静止-1.2.1.jar gwtp分派-RPC客户端 - 1.2.1.jar gwtp分派-RPC服务器-1.2.1.jar gwtp-dispatch- RPC-服务器吉斯-1.2.1.jar gwtp分派-RPC服务器 - 弹簧 - 1.2.1.jar gwtp分派-RPC-共享1.2.1.jar gwtp-MVP-客户1.2.1.jar gwtp-MVP-共享1.2.1.jar gwtp处理器-1.2.1.jar gwtp测试器-1.2.1.jar GWT-用户2.6.1.jar hibernate-commons-annotations-4.0.4.Final。罐子冬眠核-4.3.5.Final.jar冬眠-的EntityManager-4.3.5.Final.jar冬眠-JPA-2.1-API-1.0.0.Final.jar HSQLDB-2.3.2.jar杰克逊 - 注解-2.3 .0.jar杰克逊的注解-2.3.0-所以 urces.jar jandex-1.1.0.Final.jar了Javassist-3.18.1-GA.jar javax.inject-1.jar的jboss-测井3.1.3.GA.jar的jboss-记录的注解,1.2.0.Beta1的.jar的jboss-交易api_1.2_spec-1.0.0.Final.jar JSON-20090211.jar jsr305-1.3.9.jar JSR311的API-1.1.1.jar行家伪影3.1.1.jar丛-utils的-3.0.15.jar servlet的API-2.5.jar弹簧AOP-3.2.3.RELEASE.jar弹簧豆-3.2.3.RELEASE.jar弹簧上下文3.2.3.RELEASE.jar弹簧芯 - 3.2.3.RELEASE.jar弹簧表达-3.2.3.RELEASE.jar弹簧网络3.2.3.RELEASE.jar验证-API-1.0.0.GA.jar验证-API 1.0.0.GA- sources.jar速度-1.7.jar XML的API-1.0.b2.jar
我改变了的pom.xml这样:
<!-- 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>
但仍然没有成功...
我插了依赖关系树的屏幕截图。 我的信誉不允许粘贴图像。 它存储在这里: