选择使用工作区内的资源运行服务器时,在RAD 8中部署和运行spring app时出错

时间:2013-06-01 14:22:34

标签: java websphere rad

我的申请有四个小项目:

  • build-project - 只有根POM
  • ear-module - 这是包含Web项目的应用程序ear项目
  • web-project - 这是网络应用
  • utility-project - Web项目使用它作为依赖项,这个jar包含在jar中 没有EJB。

我正在使用RAD 8,当我选择使用RAD8中的Websphere“Run server with resources on Server”的发布设置运行应用程序时,部署正常工作。

但是,当我尝试使用“在服务器中运行带有资源的服务器”并在浏览器中打开应用程序时,它会失败,并显示以下错误消息:

[6/1/13 1:44:04:678 EDT] 0000001c annotations   W com.ibm.ws.amm.scan.context.ScannerContextImpl getInputDataForClass Failed to open resource [ org/springframework/web/context/ContextLoaderListener.class ] from module [ abc-web.war ]
[6/1/13 1:44:04:678 EDT] 0000001c annotations   W com.ibm.ws.amm.scan.context.ScannerContextImpl getInputDataForClass   Class loader [ org.eclipse.jst.j2ee.commonarchivecore.internal.util.WarFileDynamicClassLoader@64662b13 ]
[6/1/13 1:44:04:678 EDT] 0000001c annotations   W com.ibm.ws.amm.scan.context.ScannerContextImpl getInputDataForClass   Class loader [ com.ibm.ws.bootstrap.ExtClassLoader@d64e7229 ]
[6/1/13 1:44:04:678 EDT] 0000001c annotations   W com.ibm.ws.amm.scan.context.ScannerContextImpl getInputDataForClass   Class loader [ org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@e9f56141 ]
[6/1/13 1:44:04:678 EDT] 0000001c annotations   W com.ibm.ws.amm.scan.context.ScannerContextImpl getInputDataForClass   Class loader [ sun.misc.Launcher$AppClassLoader@964626a4 ]
[6/1/13 1:44:04:678 EDT] 0000001c annotations   W com.ibm.ws.amm.scan.context.ScannerContextImpl getInputDataForClass   Class loader [ sun.misc.Launcher$ExtClassLoader@ad8046ad ]


[6/1/13 1:44:14:724 EDT] 0000001f ApplicationMg A   WSVR0220I: Application stopped: myapp-ear
[6/1/13 1:44:14:896 EDT] 0000001f CompositionUn A   WSVR0193I: Composition unit WebSphere:cuname=myapp-ear in BLA WebSphere:blaname=myapp-ear stopped.

[6/1/13 1:44:36:470 EDT] 0000001f annotation    W com.ibm.ws.webcontainer.annotation.WASAnnotationHelper collectClasses SRVE8000W: Skipped class that failed to initialize for annotation scanning.
                                 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Class.java:213)
    at com.ibm.ws.webcontainer.annotation.WASAnnotationHelper.loadClass(WASAnnotationHelper.java:753)
    at com.ibm.ws.webcontainer.annotation.WASAnnotationHelper.collectClasses(WASAnnotationHelper.java:188)
    at com.ibm.ws.webcontainer.annotation.WASAnnotationHelper.<init>(WASAnnotationHelper.java:143)
    at com.ibm.ws.webcontainer.annotation.WASAnnotationHelperManager.getAnnotationHelper(WASAnnotationHelperManager.java:63)
    at com.ibm.ws.webcontainer.metadata.WebMetaDataFactory.handOffReferenceData(WebMetaDataFactory.java:450)
    at com.ibm.ws.webcontainer.metadata.WebMetaDataFactory.createMetaData(WebMetaDataFactory.java:423)
    at com.ibm.ws.runtime.component.MetaDataMgrImpl.createMetaDataFromFactories(MetaDataMgrImpl.java:228)
    at com.ibm.ws.runtime.component.MetaDataMgrImpl.createMetaData(MetaDataMgrImpl.java:411)
    at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:630)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:967)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:766)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1354)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2150)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:445)

这是构建项目的maven pom(根项目只是为了构建)

<groupId>com.mytest</groupId>
<artifactId>myapp</artifactId>
<version>2.0.0</version>
<packaging>pom</packaging>
<name>myapp</name>
<properties>
    <project.build.source>1.6</project.build.source>
    <project.build.target>1.6</project.build.target>
    <project.encoding>UTF-8</project.encoding>
    <springVersion>3.2.1.RELEASE</springVersion>
</properties>
<modules>
    <module>../myapp-domain</module>
    <module>../myapp-web</module>
    <module>../myapp-ear</module>
</modules>
<dependencyManagement>
    <dependencies>
        <!-- external dependencies -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springVersion}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springVersion}</version>
            <scope>compile</scope>
        </dependency>           
        <dependency>
            <groupId>opensymphony</groupId>
            <artifactId>oscache</artifactId>
            <version>2.4</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        .......   other dependencies  .......
        <!-- test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
</dependencyManagement>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${project.build.source}</source>
                    <target>${project.build.target}</target>
                    <encoding>${project.encoding}</encoding>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <encoding>${project.encoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <disableXmlReport>true</disableXmlReport>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>2.0-beta-6</version>
            </plugin>

这是耳朵项目的maven pom

<parent>
    <groupId>com.mytest</groupId>
    <artifactId>myapp</artifactId>
    <version>2.0.0</version>
</parent>
<artifactId>myapp-ear</artifactId>
<packaging>ear</packaging>
<name>MyappEAR</name>

  <dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>myapp-web</artifactId>
        <type>war</type>
        <version>2.0.0</version>
    </dependency>
</dependencies>    

<build>
    <finalName>myapp</finalName>
    <resources>
        <resource>
            <directory>META-INF</directory>
            <targetPath>../myapp/META-INF</targetPath>
            <includes>
                <include>**/*.*</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.7</version>
            <configuration>
            <applicationXml>${basedir}/META-INF/application.xml</applicationXml> 
               <generateApplicationXml>false</generateApplicationXml>
                <modules>
                    <webModule>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>myapp-web</artifactId>
                        <bundleFileName>myapp-web.war</bundleFileName>
                    </webModule>
                </modules>
                <encoding>${project.encoding}</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>
   <properties>
<maven.ear.final.name>myapp.ear</maven.ear.final.name>
</properties>

=============================================== ================================================== = 这是Web项目POM

<artifactId>myapp-web</artifactId>
<packaging>war</packaging>
<name>myappWeb</name>
<dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${springVersion}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${springVersion}</version>
    </dependency>


<build>
    <finalName>myapp-web</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <warSourceDirectory>src/main/webapp</warSourceDirectory>
                <webXml>src/main/webapp/WEB-INF/web.xml</webXml>

                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

奇怪的是,当我尝试通过右键单击服务器在Websphere 8的添加和删除选项中添加耳朵时,我看到生成的耳朵已经生成了 像这样的结构。所以它在同一场战争中有两场战争。但我查看了构建的myapp.ear文件,其中只有一个战争。

MyApp的耳

| -myapp幅

| | -Spring-web的3.2.1RELEASE.jar

| | -myapp-domain jar

|

| -myapp-web.war中

2 个答案:

答案 0 :(得分:6)

这是RAD的部署机制中的一个错误,在版本&gt; = 3.2.0中使用Spring的maven项目,并在此bug报告中记录: https://jira.springsource.org/browse/SPR-10494

有两种方法可以解决您的问题:

  1. 使用Spring版本&lt; 3.2,例如3.1.4
  2. 如果你依赖于Spring 3.2,你可以简单地将spring-web依赖项复制到临时文件夹中,只要你的工作区复制项目,然后再将其部署到websphere。它可以在下面找到 “ YOURWORKSPACE.metadata.plugins \ org.eclipse.wst.server.core \ tmpX * \ lib ”(服务器视图中的每个服务器都有自己的临时文件夹,所以如果您只有一台服务器,则该文件夹将为tmp0
  3. 第二个选项更多是一种解决方法,只有直接从IDE中部署才需要。如果您将Web项目导出为.war文件并将其手动部署到Websphere,它将起作用。

    还有另一种解决方法,我只在自己调查问题时阅读,但没有尝试自己,也找不到链接,所以要小心处理。根据这一点,您可以将实际源包装到一个新项目中,并在您的Web项目中包含具有所需依赖项的jar

    修改 我们试用了Spring 4.0.0并且bug已经消失了,所以如果你没有使用较低的Spring版本,这可能是最好的解决方案。

答案 1 :(得分:0)

正如例外所述,它是ClassNotFoundException。这意味着必要的弹簧罐在provided范围内定义,并且您的部署无法在运行时解析它。

此外: 我没有看到您正确定义了多模块依赖项。如果build-project(类型为war)将utility jar定义为provided范围内的依赖项,则需要将其与ear捆绑在一起。

如果您的utility广告素材无法在多个war文件中正确共享,则可以通过在utility范围内将compile添加到build-project

来对其进行问题排查

希望这有帮助