java - 在 IntelliJ Java 应用程序 SLF4j 记录器错误中运行 Tomcat

标签 java tomcat intellij-idea war slf4j

如果我直接在独立的 Tomcat 8 上部署我的应用程序,服务器将毫无错误地启动。只有当我尝试在 IntelliJ 中启动 Tomcat 时,我得到了这个 NoClassDefFoundError: org/slf4j/Logger 并且应用程序没有启动。当我直接在外部 Tomcat 中部署 WAR 时一切正常。 附上两个POM文件: 我已经看过 SO 上提供的解决方案,但这种情况是 IntelliJ 独有的。 NoClassDefFoundError: org/slf4j/Logger

父 POM

 <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>org.akaza.openclinica</groupId>
<artifactId>OpenClinica</artifactId>
<packaging>pom</packaging>
<version>MAINLINE-SNAPSHOT</version>
<name>OpenClinica</name>
<description>OpenClinica</description>

<modules>
    <module>core</module>
    <module>web</module>
    <module>ws</module>
</modules>

... org.slf4j slf4j-jdk14 1.6.4 org.slf4j slf4j-api 1.7.6 org.slf4j slf4j-log4j12 1.7.6 org.slf4j 七月到 slf4j 1.7.6 org.slf4j jcl-over-slf4j 1.7.6 ch.qos.logback logback-核心 1.1.2 ch.qos.logback logback-经典 1.1.2 ch.qos.logback 登录访问 1.1.2 ...

</dependencyManagement>


<!-- These dependencies are used by _all_ child projects -->
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <delimiters>
                        <delimiter>${*}</delimiter>
                    </delimiters>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skipTests>${skipTests}</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <outputDirectory>${openclinica.distros.dir}</outputDirectory>
                    <descriptors>
                        <descriptor>${project.basedir}/src/assemble/openclinica-assemble.xml</descriptor>
                    </descriptors>
                    <appendAssemblyId>false</appendAssemblyId>
                    <finalName>${assembly.name}-${project.version}</finalName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <addVersionToProjectName>true</addVersionToProjectName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.5.0</version>
                <configuration>
                    <!-- Container configuration -->
                    <container>
                        <containerId>tomcat6x</containerId>
                        <home>${catalina.home}</home>
                    </container>
                    <configuration>
                        <home>${catalina.home}</home>
                        <type>existing</type>
                    </configuration>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-plugin</artifactId>
                <version>1.9.1.0</version>
                <configuration>
                    <propertyFile>${config.file}</propertyFile>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.zeroturnaround</groupId>
                <artifactId>jrebel-maven-plugin</artifactId>
                <version>1.1.6</version>
                <executions>
                    <execution>
                        <id>generate-rebel-xml</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>buildnumber</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                        <configuration>
                            <doCheck>false</doCheck>
                            <doUpdate>false</doUpdate>
                            <shortRevisionLength>12</shortRevisionLength>
                            <buildNumberPropertyName>changeSet</buildNumberPropertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>timestamp</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>create-timestamp</goal>
                        </goals>
                        <configuration>
                            <timestampPropertyName>changeSetDate</timestampPropertyName>
                            <timestampFormat>yyyy-MM-dd HH:mm Z</timestampFormat>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.1</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>src/main/webapp/WEB-INF/schemas</schemaDirectory>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
        </plugins>
    </pluginManagement>


    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.github.jsimone</groupId>
                                <artifactId>webapp-runner</artifactId>
                                <version>8.0.33.0</version>
                                <destFileName>webapp-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>


    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>**/*.properties</exclude>
                <exclude>**/*.xml</exclude>
            </excludes>
        </resource>
    </resources>


    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
        </testResource>
    </testResources>

    <!--
    <filters>
        <filter>src/main/filters/default.properties</filter>
        <filter>src/main/filters/${config.id}.properties</filter>
    </filters>
    -->

</build>
<scm>
    <connection>scm:git:${git.url}</connection>
    <developerConnection>scm:git:${git.url}</developerConnection>
    <tag>HEAD</tag>
</scm>

<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>libs-release</name>
        <url>http://dev.openclinica.com/artifactory/libs-release</url>
    </repository>
    <repository>
        <snapshots/>
        <id>snapshots</id>
        <name>libs-snapshot</name>
        <url>http://dev.openclinica.com/artifactory/libs-snapshot</url>
    </repository>
    <repository>
        <id>jboss-public-repository-group</id>
        <name>JBoss Public Repository Group</name>
        <url>http://repository.jboss.org/nexus/content/groups/public/</url>
        <layout>default</layout>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>plugins-release</name>
        <url>http://dev.openclinica.com/artifactory/plugins-release</url>
    </pluginRepository>
    <pluginRepository>
        <snapshots/>
        <id>snapshots</id>
        <name>plugins-snapshot</name>
        <url>http://dev.openclinica.com/artifactory/plugins-snapshot</url>
    </pluginRepository>
    <pluginRepository>
        <id>jboss-public-repository-group</id>
        <name>JBoss Public Repository Group</name>
        <url>http://repository.jboss.org/nexus/content/groups/public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<distributionManagement>
    <repository>
        <id>openclinica-artifactory</id>
        <name>dev.openclinica.com-releases</name>
        <url>http://dev.openclinica.com/artifactory/libs-release-local</url>
    </repository>
    <snapshotRepository>
        <id>openclinica-artifactory</id>
        <name>dev.openclinica.com-snapshots</name>
        <url>http://dev.openclinica.com/artifactory/libs-snapshot-local</url>
    </snapshotRepository>
</distributionManagement>

子 POM

   <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>
<artifactId>OpenClinica-web</artifactId>
<packaging>war</packaging>
<name>OpenClinica Web Application</name>
<parent>
    <groupId>org.akaza.openclinica</groupId>
    <artifactId>OpenClinica</artifactId>
    <version>MAINLINE-SNAPSHOT</version>
</parent>
<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>OpenClinica-core</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sf.saxon</groupId>
        <artifactId>saxon</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sf.saxon</groupId>
        <artifactId>saxon-dom</artifactId>
    </dependency>

    <dependency>
        <groupId>rome</groupId>
        <artifactId>rome-fetcher</artifactId>
        <scope>compile</scope>
        <exclusions>
            <!-- We are using jdom 1.1 lib below -->
            <exclusion>
                <groupId>jdom</groupId>
                <artifactId>jdom</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>rome</groupId>
        <artifactId>rome</artifactId>
        <scope>compile</scope>
        <exclusions>
            <!-- We are using jdom 1.1 lib below -->
            <exclusion>
                <groupId>jdom</groupId>
                <artifactId>jdom</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.mockrunner.jdk15.jee5</groupId>
        <artifactId>mockrunner</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.mockrunner.jdk15.jee5</groupId>
        <artifactId>mockrunner-servlet</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>transaction-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.pjl-comp-filter</groupId>
        <artifactId>pjl-comp-filter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-acl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>

    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>

    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib-nodep</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
    </dependency>
    <dependency>
        <groupId>opensymphony</groupId>
        <artifactId>sitemesh</artifactId>
    </dependency>
    <dependency>
        <groupId>com.lowagie</groupId>
        <artifactId>itext</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.jmesa</groupId>
        <artifactId>jmesa</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>commons-validator</groupId>
        <artifactId>commons-validator</artifactId>
        <scope>compile</scope>
    </dependency>
    <!-- Needed by commons-validator -->
    <dependency>
        <groupId>oro</groupId>
        <artifactId>oro</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-math</groupId>
        <artifactId>commons-math</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-digester</groupId>
        <artifactId>commons-digester</artifactId>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>commons-collections</artifactId>
                <groupId>commons-collections</groupId>
            </exclusion>
            <exclusion>
                <artifactId>xml-apis</artifactId>
                <groupId>xml-apis</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>httpunit</groupId>
        <artifactId>httpunit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jdom</groupId>
        <artifactId>jdom</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.jexcelapi</groupId>
        <artifactId>jxl</artifactId>
        <scope>compile</scope>
    </dependency>
    <!-- Struts web framework -->
    <dependency>
        <groupId>struts</groupId>
        <artifactId>struts</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
    </dependency>
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz-oracle</artifactId>
    </dependency>

    <!-- XML serializer-->
    <dependency>
        <groupId>net.sf.json-lib</groupId>
        <artifactId>json-lib</artifactId>
        <version>2.4</version>
        <classifier>jdk15</classifier>
    </dependency>
    <dependency>
        <groupId>xom</groupId>
        <artifactId>xom</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sf.ezmorph</groupId>
        <artifactId>ezmorph</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-spring</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-asm</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.ws/spring-ws-core -->
    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-web</artifactId>
    </dependency>
    <!--<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>-->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
    </dependency>
    <dependency>
        <groupId>com.stormpath.spring</groupId>
        <artifactId>stormpath-default-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.ws.commons.schema</groupId>
        <artifactId>XmlSchema</artifactId>
    </dependency>
    <dependency>
        <groupId>org.codehaus.castor</groupId>
        <artifactId>castor-core</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.xmlgraphics</groupId>
        <artifactId>batik-svg-dom</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
</dependencies>

非常感谢任何帮助。

最佳答案

org.slf4j.Logger 接口(interface)包含在 slf4j-api jar 中。您已经指出该 jar(版本 1.7.6)包含在父 pom 的 dependencyManagement 部分中,但您没有显示实际的依赖关系。它是否有provided 或其他一些非默认范围?

无论如何,当您尝试通过 IntelliJ 运行您的应用程序时,您的 NoClassDefFound 错误表明该 jar 不在类路径中。

关于java - 在 IntelliJ Java 应用程序 SLF4j 记录器错误中运行 Tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38570528/

相关文章:

java - 只要用户输入不等于某些单词就运行的 while 循环不起作用?

java - 我如何告诉 Eclipse 插件本地库驻留在外部插件的位置?

Eclipse : Starting tomcat server from eclipse , 不启动已部署的 war

apache-spark - 通过 intellij 在我的本地机器上启动时如何存储 spark 的日志输出?

java 三元运算符内部 + intellij 评估表达式

java - @RequestParam名称包含方括号[]

apache - 无法从 apache php 访问 solr XML url

Spring-Boot Tomcat 配置

java - intellij 中的 Jshell 不允许泛型类型

java - 函数的 Junit 测试