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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16873674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 00:13:44  来源:igfitidea点击:

Error while deploying and running spring app in RAD 8 when selecting Run server with resources within workspace

javawebsphererad

提问by user2442578

My application has four small projects:

我的申请有四个小项目:

  • build-project - Has only the root POM
  • ear-module - This is the application ear project which contains a web project
  • web-project - This is web app
  • utility-project - Web project uses this as dependency and this jar is included as jar No EJBs.
  • build-project - 只有根 POM
  • ear-module - 这是包含一个 web 项目的应用程序 ear 项目
  • web-project - 这是网络应用程序
  • 实用程序项目 - Web 项目将此用作依赖项,并且此 jar 包含为 jar 无 EJB。

I am using RAD 8, Deployment works correctly when I select to run the application with the Publishing settings for Websphere "Run server with resources on Server" in RAD8.

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

However when I try do the same with "`Run server with resources within the workspace" and open the application in my Browser it fails with this error message:

但是,当我尝试对“`使用工作区中的资源运行服务器”执行相同操作并在我的浏览器中打开该应用程序时,它会失败并显示以下错误消息:

[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)

Here is the maven pom for the build project( root project just to do build)

这是构建项目的 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>

Here is the maven pom for the ear project

这是耳朵项目的 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>

================================================================================================== Here is the Web project POM

================================================== ================================================ 这里是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>

Strange thing is that when I try to Add the ear in Add and remove option of the Websphere 8 by rightclicking onthe server I see that the ear generated has structure like this. So it has two wars in the same war. But I looked at the myapp.ear file built and it has only one war in it.

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

myapp-ear

我的出现

|-myapp-web

|-myapp-web

|   |-Spring-web-3.2.1RELEASE.jar

| |-Spring-web-3.2.1RELEASE.jar

|   |-myapp-domain jar

| |-myapp-domain jar

|-myapp-web.war

|-myapp-web.war

回答by Tobi Nonymous

This is a bug in the deployment mechanism of the RAD with maven projects using Spring in versions >= 3.2.0 and is documented in this bugreport: https://jira.springsource.org/browse/SPR-10494

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

There are two possible ways of resolving your issue:

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

  1. Use a Spring version < 3.2, e.g. 3.1.4
  2. If you depend on Spring 3.2, you can simply copy the spring-web dependency into the temp folder whre your workspace copies your project before actually deploying it to websphere. It can be found under "YOURWORKSPACE.metadata.plugins\org.eclipse.wst.server.core\tmpX*\lib" (each server in your servers view gets its own temp folder, so if you just have one server, the folder will be tmp0
  1. 使用低于 3.2 的 Spring 版本,例如 3.1.4
  2. 如果您依赖 Spring 3.2,您可以简单地将 spring-web 依赖项复制到临时文件夹中,在您的工作区将项目实际部署到 websphere 之前,该文件夹将复制您的项目。它可以在“ YOURWORKSPACE.metadata.plugins\org.eclipse.wst.server.core\tmpX*\lib”下找到(服务器视图中的每个服务器都有自己的临时文件夹,所以如果你只有一台服务器,文件夹将是 tmp0

The second option is more of a workaround, which is only required for deployments directly from within the IDE. If you export your web project as a .war file and deploy it manually to Websphere it will just work.

第二个选项更像是一种解决方法,只有直接从 IDE 内进行部署才需要它。如果您将 Web 项目导出为 .war 文件并手动将其部署到 Websphere,它就会正常工作。

There exists another workaround, that I only read when investigating the problem myself, but didn't try out myself and can't find the link either, so handle with care. According to that you can package your actual source into a new project and including that jar in your web project with the required dependencies

还有另一种解决方法,我只在自己调查问题时阅读,但没有亲自尝试,也找不到链接,因此请谨慎处理。据此,您可以将实际源代码打包到一个新项目中,并将该 jar 包含在具有所需依赖项的 Web 项目中

edit:We tried out Spring 4.0.0 and the bug was gone, so this might be the best solution if you are not stuck with a lower Spring version.

编辑:我们尝试了 Spring 4.0.0 并且错误消失了,因此如果您不使用较低的 Spring 版本,这可能是最好的解决方案。

回答by Chris

As the exception says, it is ClassNotFoundException. This means that necessary spring jars are defined at providedscope and your deployment is failing to resolve it at runtime.

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

Also: I don't see that you have defined your multi-module dependencies correctly. If build-project(which is of type war) defines utilityjar as a dependency at providedscope, it needs to be bundled with ear.

另外:我没有看到您正确定义了多模块依赖项。如果build-project(属于war 类型)将utilityjar定义为provided作用域的依赖项,则需要将其与ear 捆绑在一起。

If your utilityjar is not correctly being shared across multiple war files, you could troubleshoot it by adding utilityat compilescope to build-project

如果你的utility罐子没有被正确地跨多个WAR文件共享,你可以通过添加解决它utilitycompile范围build-project

Hope this helps

希望这可以帮助