转换为Mauts构建在Struts DynaValidatorForm之后的ClassNotFoundException

时间:2011-06-11 20:17:41

标签: maven struts classnotfoundexception

我最近在我的Struts web项目上设置了Maven,在将生成的EAR部署到Websphere Application Server之后,我在Struts的DynaValidatorForm类上获得了ClassNotFoundExceptions。这似乎与JAR无关,所以我觉得这与maven创建的类文件有关,这些类文件与我正在使用的struts版本不兼容,尽管我没有编译时错误。

潜在线索:

  • DynaValidatorForm类存在于struts-1.1 jar文件中,该文件包含在WEB-INF / lib目录中的EAR中。
  • 为了确保我没有maven转换引起的依赖性问题,我用所有以前的jar(pre-maven和pre-broken)替换了EAR中的所有jar,然后我得到了(顺便提一下相同的源代码)。
  • 接下来,我尝试交换生成的类文件,而不是交换jar;我将maven构建的EAR中引用DynaValidatorForm的所有类文件替换为非maven构建的EAR中的相同类,并且当我在Websphere中安装它时,我没有错误。非maven构建的EAR是使用Rational Application Developer(Eclipse)的简单EAR导出构建的。

类交换工作的事实让我觉得问题在于maven生成的类文件,但我不知道问题是什么。 Java版本差异是我唯一可以想到的,但Struts在我的旧构建过程中使用Java 5工作得很好,而且我或者相信我无论如何,使用1.5使用maven构建源代码,因为我有一个maven- source-plugin定义,源和目标设置为1.5。我很困惑。

有没有人有任何想法?非常感谢您提出的任何建议。

更新:

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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc</groupId>
<artifactId>app</artifactId>
<packaging>war</packaging>
<version>1.0.4</version>
<name>app</name>

<dependencies>
    <dependency>
        <groupId>struts</groupId>
        <artifactId>struts</artifactId>
        <version>1.1</version>
    </dependency>

    ... more unrelated dependencies ...
</dependencies>
<build>
    <resources>
        <resource>
            <filtering>false</filtering>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <filtering>false</filtering>
            <directory>src/main/java</directory>
            <includes>
                <include>**</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <filtering>false</filtering>
            <directory>src/test/java</directory>
            <includes>
                <include>**</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <configuration>
                <downloadSources>true</downloadSources>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

堆栈追踪:

[6/11/11 15:52:10:436 EDT] 00000014 ActionServlet E org.apache.struts.action.ActionServlet handleConfigException Parsing error processing resource path 
                             java.lang.reflect.InvocationTargetException
at org.apache.commons.digester.Digester.createSAXException(Digester.java:2792)
at org.apache.commons.digester.Digester.createSAXException(Digester.java:2818)
at org.apache.commons.digester.Digester.startElement(Digester.java:1289)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1572)
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:1006)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:955)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:470)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:227)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:341)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:1308)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:174)
at com.ibm.wsspi.webcontainer.extension.WebExtensionProcessor.createServletWrapper(WebExtensionProcessor.java:99)
at com.ibm.ws.webcontainer.webapp.WebApp.getServletWrapper(WebApp.java:902)
at com.ibm.ws.webcontainer.webapp.WebApp.getServletWrapper(WebApp.java:824)
at com.ibm.ws.webcontainer.webapp.WebApp.initializeTargetMappings(WebApp.java:542)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:379)
at com.ibm.ws.wswebcontainer.webapp.WebApp.initialize(WebApp.java:293)
at com.ibm.ws.wswebcontainer.webapp.WebGroup.addWebApplication(WebGroup.java:93)
at com.ibm.ws.wswebcontainer.VirtualHost.addWebApplication(VirtualHost.java:162)
at com.ibm.ws.wswebcontainer.WebContainer.addWebApp(WebContainer.java:673)
at com.ibm.ws.wswebcontainer.WebContainer.addWebApplication(WebContainer.java:626)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:335)
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:551)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1250)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1140)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:569)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:819)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:921)
at com.ibm.ws.runtime.component.ApplicationMgrImpl$AppInitializer.run(ApplicationMgrImpl.java:2100)
at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:342)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1497)
---- Begin backtrace for Nested Throwables
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)
at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1684)
at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1713)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at org.apache.commons.digester.SetPropertiesRule.begin(SetPropertiesRule.java:217)
at org.apache.commons.digester.Rule.begin(Rule.java:152)
at org.apache.commons.digester.Digester.startElement(Digester.java:1286)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1572)
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:1006)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:955)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:470)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:227)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:341)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:1308)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:174)
at com.ibm.wsspi.webcontainer.extension.WebExtensionProcessor.createServletWrapper(WebExtensionProcessor.java:99)
at com.ibm.ws.webcontainer.webapp.WebApp.getServletWrapper(WebApp.java:902)
at com.ibm.ws.webcontainer.webapp.WebApp.getServletWrapper(WebApp.java:824)
at com.ibm.ws.webcontainer.webapp.WebApp.initializeTargetMappings(WebApp.java:542)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:379)
at com.ibm.ws.wswebcontainer.webapp.WebApp.initialize(WebApp.java:293)
at com.ibm.ws.wswebcontainer.webapp.WebGroup.addWebApplication(WebGroup.java:93)
at com.ibm.ws.wswebcontainer.VirtualHost.addWebApplication(VirtualHost.java:162)
at com.ibm.ws.wswebcontainer.WebContainer.addWebApp(WebContainer.java:673)
at com.ibm.ws.wswebcontainer.WebContainer.addWebApplication(WebContainer.java:626)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:335)
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:551)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1250)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1140)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:569)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:819)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:921)
at com.ibm.ws.runtime.component.ApplicationMgrImpl$AppInitializer.run(ApplicationMgrImpl.java:2100)
at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:342)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1497)
Caused by: java.lang.NoClassDefFoundError: DynaValidatorForm
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:266)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at com.ibm.ws.classloader.CompoundClassLoader._defineClass(CompoundClassLoader.java:577)
at com.ibm.ws.classloader.CompoundClassLoader.findClass(CompoundClassLoader.java:529)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:403)
at java.lang.ClassLoader.loadClass(ClassLoader.java:605)
at org.apache.struts.config.FormBeanConfig.formBeanClass(FormBeanConfig.java:320)
at org.apache.struts.config.FormBeanConfig.setType(FormBeanConfig.java:191)
... 50 more
Caused by: java.lang.ClassNotFoundException: DynaValidatorForm
at com.ibm.ws.classloader.CompoundClassLoader.findClass(CompoundClassLoader.java:502)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:403)
at java.lang.ClassLoader.loadClass(ClassLoader.java:605)
... 59 more

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。事实证明,RAD在类路径更改完成之前已经完成了自动构建,因为项目中的文件已经更改,这导致类具有构建错误(为什么它仍然创建类文件???)。当使用maven打包时,我假设maven会重新编译,但是它会使用这些错误的类,因为所有内容都是最新的。我可以发誓我曾经在“mvn安装”之前做了一个“mvn clean”,以确保没有发生这种情况,同样不幸的结果,但我可能会发疯了。