部署时ClassNotFoundException

时间:2015-08-17 18:14:44

标签: eclipse maven java-ee wildfly-8 switchyard

我在本地maven repo中安装了外部依赖项(ejb-client)。 Eclipse和手动maven构建看起来很好并且编译成功。它也在Maven依赖项下正确列出。

当我部署到WildFly 8.1时,运行时无法识别类并抛出异常。我之前从未遇到像这样的依赖问题。与这个项目的唯一区别是它是一个SwitchYard 2.0项目(WildFly 8.1覆盖)。我怀疑WildFly配置是由于覆盖错误,或者我错过了一些maven构建插件。

我终于使用maven shade插件解决了它,它编译了内部的依赖,但是:
我之前从未需要它,所以我不喜欢这个解决方案 2.从eclipse部署时不会自动运行,因此我必须进行手动maven构建和手动部署。如何在部署时告诉maven运行shade插件?我试图将包从部署改为部署无效。

造成问题的外部依赖是jmsprojekt-main。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>si.fri.liis.jmsprojektsy</groupId>
  <artifactId>vloga-service</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>si.fri.liis.jmsprojektsy:vloga-service</name>

  <properties>
    <switchyard.version>2.0.0.Final</switchyard.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.switchyard</groupId>
        <artifactId>switchyard-bom</artifactId>
        <version>${switchyard.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.switchyard.components</groupId>
      <artifactId>switchyard-component-bean</artifactId>
    </dependency>
    <dependency>
      <groupId>org.switchyard.components</groupId>
      <artifactId>switchyard-component-soap</artifactId>
    </dependency>
    <dependency>
      <groupId>org.switchyard</groupId>
      <artifactId>switchyard-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.switchyard</groupId>
      <artifactId>switchyard-transform</artifactId>
    </dependency>
    <dependency>
      <groupId>org.switchyard</groupId>
      <artifactId>switchyard-validate</artifactId>
    </dependency>
    <dependency>
      <groupId>org.switchyard</groupId>
      <artifactId>switchyard-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.switchyard.components</groupId>
      <artifactId>switchyard-component-test-mixin-cdi</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>si.fri.liis.jmsprojekt</groupId>
        <artifactId>jmsprojekt-main</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>ejb-client</type>
        <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.switchyard</groupId>
        <artifactId>switchyard-plugin</artifactId>
        <version>${switchyard.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>configure</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scannerClassNames>
            <param>org.switchyard.transform.config.model.TransformSwitchYardScanner</param>
          </scannerClassNames>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <includes>
                  <include>si.fri.liis.jmsprojekt:jmsprojekt-main</include>
                </includes>
              </artifactSet>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

WildFly启动日志,显示未找到依赖项的类:

20:06:26,777 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC000001: Failed to start service jboss.deployment.unit."vloga-service.jar".SwitchYardService: org.jboss.msc.service.StartException in service jboss.deployment.unit."vloga-service.jar".SwitchYardService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.8.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.8.0_51]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.8.0_51]
Caused by: java.lang.NoClassDefFoundError: si/fri/liis/jmsprojekt/data/VlogaData
    at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.8.0_51]
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source) [rt.jar:1.8.0_51]
    at java.lang.Class.privateGetPublicMethods(Unknown Source) [rt.jar:1.8.0_51]
    at java.lang.Class.getMethods(Unknown Source) [rt.jar:1.8.0_51]
    at org.switchyard.transform.internal.TransformerUtil.isTransformer(TransformerUtil.java:223)
    at org.switchyard.transform.internal.TransformerUtil.newTransformers(TransformerUtil.java:71)
    at org.switchyard.transform.internal.TransformerRegistryLoader.newTransformers(TransformerRegistryLoader.java:231)
    at org.switchyard.transform.internal.TransformerRegistryLoader.registerTransformers(TransformerRegistryLoader.java:117)
    at org.switchyard.transform.internal.TransformerRegistryLoader.registerTransformers(TransformerRegistryLoader.java:101)
    at org.switchyard.deploy.internal.Deployment.registerTransformers(Deployment.java:271)
    at org.switchyard.deploy.internal.Deployment.doInit(Deployment.java:117)
    at org.switchyard.deploy.internal.AbstractDeployment.init(AbstractDeployment.java:139)
    at org.switchyard.as7.extension.deployment.SwitchYardDeployment.start(SwitchYardDeployment.java:155)
    at org.switchyard.as7.extension.services.SwitchYardService.start(SwitchYardService.java:77)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    ... 3 more
Caused by: java.lang.ClassNotFoundException: si.fri.liis.jmsprojekt.data.VlogaData from [Module "deployment.vloga-service.jar:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.3.Final]
    ... 19 more

20:06:26,817 ERROR [stderr] (MSC service thread 1-9) Warning:  org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.

20:06:26,899 ERROR [stderr] (MSC service thread 1-9) Compiler warnings:

20:06:26,900 ERROR [stderr] (MSC service thread 1-9)   WARNING:  'org.apache.xerces.jaxp.SAXParserImpl: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.'

20:06:27,265 INFO  [org.switchyard.common.camel.SwitchYardCamelContextImpl] (MSC service thread 1-9) Route: direct:{urn:si.fri.liis.jmsprojektsy:vloga-service:1.0}VlogaServicePortType started and consuming from: Endpoint[direct://%7Burn:si.fri.liis.jmsprojektsy:vloga-service:1.0%7DVlogaServicePortType]
20:06:27,361 INFO  [org.switchyard] (MSC service thread 1-9) Addressing [enabled = false, required = false]
20:06:27,361 INFO  [org.switchyard] (MSC service thread 1-9) MTOM [enabled = false, threshold = 0]
20:06:27,443 INFO  [org.jboss.ws.cxf.metadata] (MSC service thread 1-9) JBWS024061: Adding service endpoint metadata: id=VlogaService
 address=http://localhost:8080/vloga-service/VlogaService
 implementor=org.switchyard.component.soap.endpoint.BaseWebService
 serviceName={urn:si.fri.liis.jmsprojektsy:vloga-service:1.0}VlogaService
 portName={urn:si.fri.liis.jmsprojektsy:vloga-service:1.0}VlogaServicePort
 annotationWsdlLocation=null
 wsdlLocationOverride=vfs:/C:/Users/cen/Desktop/wildfly-8.1.0.Final-sy/bin/content/vloga-service-0.0.1-SNAPSHOT.jar/VlogaService.wsdl
 mtomEnabled=false
20:06:27,982 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-9) Creating Service {urn:si.fri.liis.jmsprojektsy:vloga-service:1.0}VlogaService from WSDL: vfs:/C:/Users/cen/Desktop/wildfly-8.1.0.Final-sy/bin/content/vloga-service-0.0.1-SNAPSHOT.jar/VlogaService.wsdl
20:06:28,172 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-9) Setting the server's publish address to be http://localhost:8080/vloga-service/VlogaService
20:06:28,261 INFO  [org.jboss.ws.cxf.deployment] (MSC service thread 1-9) JBWS024074: WSDL published to: file:/C:/Users/cen/Desktop/wildfly-8.1.0.Final-sy/standalone/data/wsdl/vloga-service.deployment/VlogaService.wsdl
20:06:28,266 INFO  [org.jboss.as.webservices] (MSC service thread 1-5) JBAS015539: Starting service jboss.ws.endpoint."vloga-service.deployment".VlogaService
20:06:28,331 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-9) JBAS017534: Registered web context: /vloga-service
20:06:28,411 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "vloga-service.jar")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"vloga-service.jar\".SwitchYardService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"vloga-service.jar\".SwitchYardService: Failed to start service
    Caused by: java.lang.NoClassDefFoundError: si/fri/liis/jmsprojekt/data/VlogaData
    Caused by: java.lang.ClassNotFoundException: si.fri.liis.jmsprojekt.data.VlogaData from [Module \"deployment.vloga-service.jar:main\" from Service Module Loader]"}}
20:06:28,496 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 33) JBAS018559: Deployed "vloga-service.jar" (runtime-name : "vloga-service.jar")
20:06:28,497 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 33) JBAS018559: Deployed "vloga-service-0.0.1-SNAPSHOT.jar" (runtime-name : "vloga-service-0.0.1-SNAPSHOT.jar")
20:06:28,499 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.deployment.unit."vloga-service.jar".SwitchYardService: org.jboss.msc.service.StartException in service jboss.deployment.unit."vloga-service.jar".SwitchYardService: Failed to start service

20:06:28,751 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016009: Stopping weld service for deployment vloga-service.jar
20:06:28,803 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015877: Stopped deployment vloga-service.jar (runtime-name: vloga-service.jar) in 67ms
20:06:28,805 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
20:06:28,805 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
20:06:28,806 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.1.0.Final "Kenny" started in 17000ms - Started 287 of 340 services (98 services are lazy, passive or on-demand)
20:06:29,053 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018558: Undeployed "vloga-service.jar" (runtime-name: "vloga-service.jar")
20:06:29,054 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.deployment.unit."vloga-service.jar".SwitchYardService

1 个答案:

答案 0 :(得分:0)

解决方案是将SwitchYard项目包装到EAR中。然后正确解析依赖关系。