tomcat上的NoClassdefFoundError运行时

时间:2014-03-10 13:20:57

标签: java tomcat gwt vaadin m2eclipse

Java.lang.NoClassDefFoundError: com/google/gwt/event/dom/client/HasClickHandlers at java.lang.ClassLoader.defineClass1(Native Method) at ...

然而,在WEB-INF / lib中,有一个jar包含类......

但是tomcat表示:

INFO: validateJarFile(C:\Users\Boss\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\applicLiquidator\WEB-INF\lib\gwt-dev-2.3.0.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
márc. 10, 2014 1:54:55 DU org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Users\Boss\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\applicLiquidator\WEB-INF\lib\gwt-user-2.3.0.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

那么如何在违反servlet.class的情况下在运行时使这些类可用?

更新: 由于Servlet.class违规,并且由于运行时需要这些罐子,所以看起来像一个恶性循环:(

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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Reignsoft</groupId>
    <artifactId>Liquidator</artifactId>
    <packaging>war</packaging>
    <version>0.2</version>
    <name>Felszámoló Ügyviteli Rendszer</name>
    <ciManagement>
        <system>hudson</system>
        <url>http://reign.ti:58084/jenkins/job/Liquidator%20-%20Maven/</url>
    </ciManagement>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <vaadin.version>6.8.13</vaadin.version>
        <jpacontainer.version>2.0.0</jpacontainer.version>
        <gwt.version>2.3.0</gwt.version>
        <gwt.plugin.version>2.3.0-1</gwt.plugin.version>
        <url>http://localhost:8080/manager/text</url>
        <path>/applicLiquidator</path>
        <update>true</update>
        <username>tomcat</username>
        <password>tomcat</password>
    </properties>
    <repositories>
        <repository>
            <id>vaadin-addons</id>
            <url>http://maven.vaadin.com/vaadin-addons</url>
        </repository>
        <repository>
            <id>vaadin-snapshots</id>
            <url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>EclipseLink Repo</id>
            <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>com.vaadin.addon</groupId>
            <artifactId>jpacontainer-addon-agpl-3.0</artifactId>
            <version>${jpacontainer.version}</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.vaadin.addons</groupId>
            <artifactId>customfield</artifactId>
            <version>0.9.3</version>
        </dependency>
        <dependency>
            <groupId>com.vaadin.addon</groupId>
            <artifactId>beanvalidation-addon</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.vaadin.addons</groupId>
            <artifactId>filteringtable</artifactId>
            <version>0.8.4</version>
        </dependency>
        <dependency>
            <groupId>org.vaadin.addons</groupId>
            <artifactId>popupbutton</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin</artifactId>
            <version>${vaadin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.160</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>${gwt.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-dev</artifactId>
            <version>${gwt.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <classifier>sources</classifier>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymockclassextension</artifactId>
            <version>3.2</version>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-easymock</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.vaadin.addon</groupId>
            <artifactId>confirmdialog</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire</artifactId>
            <version>2.16</version>
            <type>pom</type>
        </dependency>
        <!-- for PDF document generatioon -->
        <!-- 1.0 rather than 1.1 due to http://apache-fop.1065347.n5.nabble.com/Maven-dependencies-for-fop-1-1-td37437.html -->
        <dependency> 
          <groupId>org.apache.xmlgraphics</groupId>
          <artifactId>fop</artifactId>
          <version>1.0</version>
        </dependency>
        <!-- for Office document generation -->
        <dependency>
            <groupId>org.docx4j</groupId>
            <artifactId>docx4j</artifactId>
            <version> 3.0.0</version>
        </dependency>
        <!-- for generating HTML pages, a HTML template engine -->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.20</version>
        </dependency>
        <!-- for drawing with GWT graphics  -->
        <!-- 
        <dependency>
           <groupId>org.vaadin.addons</groupId>
           <artifactId>gwt-graphics</artifactId>
           <version>1.0.0</version>
        </dependency> -->
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.vaadin</groupId>
                                        <artifactId>
                                            vaadin-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [1.0.2,)
                                        </versionRange>
                                        <goals>
                                            <goal>update-widgetset</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>
                                            gwt-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [${gwt.plugin.version},)
                                        </versionRange>
                                        <goals>
                                            <goal>resources</goal>
                                            <goal>compile</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <url>${url}</url>
                        <username>${username}</username>
                        <password>${password}</password>
                        <path>${path}</path>
                        <update>${update}</update>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <!-- Uncomment to enable widgetset compilation -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>gwt-maven-plugin</artifactId>
                    <version>${gwt.plugin.version}</version>
                    <configuration>
                        <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
                        <webappDirectory>${basedir}/src/main/webapp/VAADIN/widgetsets
                        </webappDirectory>
                        <hostedWebapp>${basedir}/src/main/webapp/VAADIN/widgetsets
                        </hostedWebapp>
                        <noServer>true</noServer>
                        <draftCompile>false</draftCompile>
                        <style>OBF</style>
                        <runTarget>http://localhost:8080/</runTarget>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>resources</goal>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.4.1</version>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>src/main/webapp/VAADIN/widgetsets</directory>
                            </fileset>
                        </filesets>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.vaadin</groupId>
                    <artifactId>vaadin-maven-plugin</artifactId>
                    <version>1.0.2</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>update-widgetset</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire</artifactId>
                    <version>2.16</version>
                    <configuration>
                        <excludes>
                            <exclude>**/*.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

1 个答案:

答案 0 :(得分:0)

我猜你在你的应用程序中捆绑了一个版本的Servlet。

Tomcat不喜欢这样,所以它停止加载,它根本没有到达你真正需要的类。如果您使用的是maven,请将servlet依赖项设置为:

<scope>provided</scope>

<强>更新

相关段落是:

The classloader that a container uses to load a servlet in a WAR must 
allow the developer to load any resources contained in library JARs within 
the WAR following normal J2SE semantics using getResource. 
It must not allow the WAR to override J2SE or Java servlet API classes.
It is further recommended that the loader not allow servlets in the WAR
access to the web container’s implementation classes.
It is recommended also that the application class loader be implemented
so that classes and resources packaged within the WAR are loaded in
preference to classes and resources residing in container-wide library JARs.

请发布你的maven pom依赖项并仔细检查生成的war文件是否包含一个包含servlet类的jar。