title: Log4j issue with maven and gwt: org.apache.log4j.XAppender object is not assignable
body: <p>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:</p>
  
  <blockquote>
    <p>[ERROR] log4j:ERROR A "org.apache.log4j.RollingFileAppender" object is
    not assig nable to a "org.apache.log4j.Appender" variable. [ERROR]
    log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
    [ERROR] log4j:ERROR [sun.misc.Launcher$AppClassLoader@baf1915] whereas
    object of  type [ERROR] log4j:ERROR
    "org.apache.log4j.RollingFileAppender" was loaded by [WebApp
    ClassLoader=1312837549@4e404fad]. [ERROR] log4j:ERROR Could not
    instantiate appender named "file". [ERROR] log4j:ERROR A
    "org.apache.log4j.ConsoleAppender" object is not assignabl e to a
    "org.apache.log4j.Appender" variable. [ERROR] log4j:ERROR The class
    "org.apache.log4j.Appender" was loaded by [ERROR] log4j:ERROR
    [sun.misc.Launcher$AppClassLoader@baf1915] whereas object of  type
    [ERROR] log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by
    [WebAppClas sLoader=1312837549@4e404fad]. [ERROR] log4j:ERROR Could
    not instantiate appender named "stdout".</p>
  </blockquote>
  
  <p>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:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
   &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  
   &lt;groupId&gt;testproject&lt;/groupId&gt;
   &lt;artifactId&gt;trustme-mdm-gwtp&lt;/artifactId&gt;
   &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
   &lt;packaging&gt;war&lt;/packaging&gt;
   &lt;name&gt;GWTP Basic&lt;/name&gt;
   &lt;description&gt;Basic GWTP application&lt;/description&gt;
  
  
   &lt;properties&gt;
   &lt;!-- client --&gt;
   &lt;gwt.version&gt;2.6.0&lt;/gwt.version&gt;
   &lt;gwtp.version&gt;1.2.1&lt;/gwtp.version&gt;
   &lt;gin.version&gt;2.1.2&lt;/gin.version&gt;
  
  
   &lt;!-- server --&gt;
   &lt;guice.version&gt;3.0&lt;/guice.version&gt;
  
  
   &lt;!-- testing --&gt;
   &lt;junit.version&gt;4.7&lt;/junit.version&gt;
   &lt;jukito.version&gt;1.4&lt;/jukito.version&gt;
  
  
   &lt;!-- maven --&gt;
   &lt;gwt-maven-plugin.version&gt;2.6.0&lt;/gwt-maven-plugin.version&gt;
   &lt;maven-surefire-plugin.version&gt;2.6&lt;/maven-surefire-plugin.version&gt;
   &lt;maven-compiler-plugin.version&gt;2.3.2&lt;/maven-compiler-plugin.version&gt;
   &lt;maven-resources-plugin.version&gt;2.5&lt;/maven-resources-plugin.version&gt;
   &lt;maven-processor-plugin.version&gt;2.0.5&lt;/maven-processor-plugin.version&gt;
   &lt;maven-build-helper-plugin.version&gt;1.7&lt;/maven-build-helper-plugin.version&gt;
  
  
  
  
   &lt;target.jdk&gt;1.7&lt;/target.jdk&gt;
   &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
   &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
  
  
   &lt;webappDirectory&gt;${project.build.directory}/${project.build.finalName}&lt;/webappDirectory&gt;
   &lt;/properties&gt;
  
  
   &lt;build&gt;
   &lt;outputDirectory&gt;${webappDirectory}/WEB-INF/classes&lt;/outputDirectory&gt;
  
  
   &lt;plugins&gt;
   &lt;!-- JUnit Testing - skip *.GwtTest cases --&gt;
   &lt;!-- 'mvn test' - runs the Jukito tests --&gt;
   &lt;plugin&gt;
   &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
   &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
   &lt;version&gt;${maven-surefire-plugin.version}&lt;/version&gt;
   &lt;configuration&gt;
   &lt;includes&gt;
   &lt;include&gt;**/*Test.java&lt;/include&gt;
   &lt;/includes&gt;
   &lt;excludes&gt;
   &lt;exclude&gt;**/*GwtTest.java&lt;/exclude&gt;
   &lt;/excludes&gt;
   &lt;/configuration&gt;
   &lt;/plugin&gt;
   &lt;plugin&gt;
   &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
   &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
   &lt;version&gt;2.3.2&lt;/version&gt;
   &lt;configuration&gt;
   &lt;source&gt;1.7&lt;/source&gt;
   &lt;target&gt;1.7&lt;/target&gt;
   &lt;/configuration&gt;
   &lt;/plugin&gt;
  
  
   &lt;!-- GWT --&gt;
   &lt;!-- 'mvn gwt:run' - runs development mode --&gt;
   &lt;!-- 'mvn gwt:debug' - runs debug mode --&gt;
   &lt;!-- 'mvn gwt:compile' - compiles gwt --&gt;
   &lt;!-- 'mvn integration-test' - runs the gwt tests (*GwtTest.java) --&gt;
   &lt;plugin&gt;
   &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
   &lt;artifactId&gt;gwt-maven-plugin&lt;/artifactId&gt;
   &lt;version&gt;${gwt.version}&lt;/version&gt;
   &lt;configuration&gt;
   &lt;!-- With multiple tests use GwtTestSuite.java for speed --&gt;
   &lt;includes&gt;**/*GwtTest.java&lt;/includes&gt;
   &lt;extraJvmArgs&gt;-Xss1024K -Xmx1024M -XX:MaxPermSize=256M&lt;/extraJvmArgs&gt;
  
  
   &lt;copyWebapp&gt;true&lt;/copyWebapp&gt;
   &lt;hostedWebapp&gt;${webappDirectory}&lt;/hostedWebapp&gt;
  
  
   &lt;runTarget&gt;Project.html&lt;/runTarget&gt;
   &lt;modules&gt;
   &lt;module&gt;testproject.Project&lt;/module&gt;
   &lt;/modules&gt;
   &lt;/configuration&gt;
   &lt;executions&gt;
   &lt;execution&gt;
   &lt;goals&gt;
   &lt;goal&gt;compile&lt;/goal&gt;
   &lt;goal&gt;test&lt;/goal&gt;
   &lt;/goals&gt;
   &lt;/execution&gt;
   &lt;/executions&gt;
   &lt;/plugin&gt;
   &lt;/plugins&gt;
   &lt;/build&gt;
  
  
   &lt;dependencies&gt;
   &lt;!-- Google Web Toolkit --&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
   &lt;artifactId&gt;gwt-user&lt;/artifactId&gt;
   &lt;version&gt;${gwt.version}&lt;/version&gt;
   &lt;/dependency&gt;
  
  
   &lt;!-- GWT-Platform --&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;com.gwtplatform&lt;/groupId&gt;
   &lt;artifactId&gt;gwtp-all&lt;/artifactId&gt;
   &lt;version&gt;${gwtp.version}&lt;/version&gt;
   &lt;/dependency&gt;
  
  
   &lt;!-- DI --&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;com.google.inject&lt;/groupId&gt;
   &lt;artifactId&gt;guice&lt;/artifactId&gt;
   &lt;version&gt;${guice.version}&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;com.google.inject.extensions&lt;/groupId&gt;
   &lt;artifactId&gt;guice-servlet&lt;/artifactId&gt;
   &lt;version&gt;${guice.version}&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;com.google.inject.extensions&lt;/groupId&gt;
   &lt;artifactId&gt;guice-assistedinject&lt;/artifactId&gt;
   &lt;version&gt;${guice.version}&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;com.google.gwt.inject&lt;/groupId&gt;
   &lt;artifactId&gt;gin&lt;/artifactId&gt;
   &lt;version&gt;${gin.version}&lt;/version&gt;
   &lt;/dependency&gt;
  
  
   &lt;!-- Test --&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;junit&lt;/groupId&gt;
   &lt;artifactId&gt;junit&lt;/artifactId&gt;
   &lt;version&gt;${junit.version}&lt;/version&gt;
   &lt;scope&gt;test&lt;/scope&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;org.jukito&lt;/groupId&gt;
   &lt;artifactId&gt;jukito&lt;/artifactId&gt;
   &lt;version&gt;${jukito.version}&lt;/version&gt;
   &lt;scope&gt;test&lt;/scope&gt;
   &lt;/dependency&gt;
   &lt;!-- Hibernate --&gt;
   &lt;!-- for JPA, use hibernate-entitymanager instead of hibernate-core --&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
   &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
   &lt;version&gt;4.3.5.Final&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;!-- hSQLDB --&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
   &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
   &lt;version&gt;2.3.2&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;!-- add slf4j interfaces to classpath --&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
   &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
   &lt;version&gt;1.7.7&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;!--  GWT-Log --&gt;
   &lt;dependency&gt;
   &lt;groupId&gt;com.allen-sauer.gwt.log&lt;/groupId&gt;
   &lt;artifactId&gt;gwt-log&lt;/artifactId&gt;
   &lt;version&gt;3.3.0&lt;/version&gt;
   &lt;/dependency&gt;
  
   &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>When I take a look at the \target...\lib folder, these are the jars that are deployed:</p>
  
  <blockquote>
    <p>antlr-2.7.7.jar aopalliance-1.0.jar commons-collections-3.2.1.jar
    commons-lang-2.4.jar commons-logging-1.1.1.jar dom4j-1.6.1.jar
    gin-2.1.2.jar guava-16.0.1.jar guava-gwt-16.0.1.jar guice-3.0.jar
    guice-assistedinject-3.0.jar guice-servlet-3.0.jar
    gwt-jackson-0.4.0.jar gwt-log-3.3.0.jar gwtp-all-1.2.1.jar
    gwtp-clients-common-1.2.1.jar gwtp-crawler-1.2.1.jar
    gwtp-dispatch-common-client-1.2.1.jar
    gwtp-dispatch-common-shared-1.2.1.jar gwtp-dispatch-rest-1.2.1.jar
    gwtp-dispatch-rpc-client-1.2.1.jar gwtp-dispatch-rpc-server-1.2.1.jar
    gwtp-dispatch-rpc-server-guice-1.2.1.jar
    gwtp-dispatch-rpc-server-spring-1.2.1.jar
    gwtp-dispatch-rpc-shared-1.2.1.jar gwtp-mvp-client-1.2.1.jar
    gwtp-mvp-shared-1.2.1.jar gwtp-processors-1.2.1.jar
    gwtp-tester-1.2.1.jar gwt-user-2.6.1.jar
    hibernate-commons-annotations-4.0.4.Final.jar
    hibernate-core-4.3.5.Final.jar hibernate-entitymanager-4.3.5.Final.jar
    hibernate-jpa-2.1-api-1.0.0.Final.jar hsqldb-2.3.2.jar
    jackson-annotations-2.3.0.jar jackson-annotations-2.3.0-sources.jar
    jandex-1.1.0.Final.jar javassist-3.18.1-GA.jar javax.inject-1.jar
    jboss-logging-3.1.3.GA.jar jboss-logging-annotations-1.2.0.Beta1.jar
    jboss-transaction-api_1.2_spec-1.0.0.Final.jar json-20090211.jar
    jsr305-1.3.9.jar jsr311-api-1.1.1.jar maven-artifact-3.1.1.jar
    plexus-utils-3.0.15.jar servlet-api-2.5.jar
    spring-aop-3.2.3.RELEASE.jar spring-beans-3.2.3.RELEASE.jar
    spring-context-3.2.3.RELEASE.jar spring-core-3.2.3.RELEASE.jar
    spring-expression-3.2.3.RELEASE.jar spring-web-3.2.3.RELEASE.jar
    validation-api-1.0.0.GA.jar validation-api-1.0.0.GA-sources.jar
    velocity-1.7.jar xml-apis-1.0.b2.jar</p>
  </blockquote>
  
  <p>I changed the pom.xml to this:</p>
  
  <pre><code>&lt;!-- Google Web Toolkit --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
      &lt;artifactId&gt;gwt-servlet&lt;/artifactId&gt;
      &lt;version&gt;${gwt.version}&lt;/version&gt;
      &lt;scope&gt;runtime&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
      &lt;artifactId&gt;gwt-user&lt;/artifactId&gt;
      &lt;version&gt;${gwt.version}&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>But still no success...</p>
  
  <p>I inserted a screenshot of the dependency tree. My reputation does not allow to paste images. It is stored here:</p>
  
  <p><a href="https://i.stack.imgur.com/yfSiq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yfSiq.png" alt="Dependency tree"></a></p>