【问题标题】:Deployment on WildFLy 8 failsWildFLy 8 上的部署失败
【发布时间】:2014-05-22 16:48:28
【问题描述】:

我正在尝试在 Wildfly 8 上部署我的 Web 应用程序,但出现错误。错误指出The deployment scanner found a directory named META-INF that was not inside a directory whose name ends with .ear, .jar, .rar, .sar or .war.。这是一个奇怪的问题,因为我的 web.xml 位于 src/main/webapp/WEB-INF/ 目录中,并且构建的包确实以 .war 结尾。

我也尝试过部署一个由 Maven 生成的简单 webapp。是maven-archetype-webapp部署失败 并显示相同的错误消息。见下文:

ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015010: The deployment scanner found a directory named META-INF that was not inside a directory whose name ends with .ear, .jar, .rar, .sar or .war. This is likely the result of unzipping an archive directly inside the /opt/wildfly8/standalone/deployments directory, which is a user error. The META-INF directory will not be scanned for deployments, but it is possible that the scanner may find other files from the unzipped archive and attempt to deploy them, leading to errors.
09:40:43,353 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "WebApp" (runtime-name: "WebApp")
09:40:43,354 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "pom.xml" (runtime-name: "pom.xml")
09:40:43,843 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "WebApp" (runtime-name : "WebApp")
09:40:43,844 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "pom.xml" (runtime-name : "pom.xml")

这是 WildFly 中的错误还是什么?由于生成的 Maven 项目也失败了,这让我觉得它可能是一个错误。



编辑

我现在已经尝试了 WildFly 快速入门项目,他们的 helloworld 应用程序 (https://github.com/wildfly/quickstart/tree/master/helloworld) 在我的 WildFly 实例上运行良好。但是当我将 web.xml 添加到 helloworld 项目并将 servlet 代码更改为我自己的 servlet 代码和 pom.xml 以使其与我的设置相对应时,我得到了错误。

04:50:28,073 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "MyService.war" (runtime-name: "MyService.war")
04:50:28,236 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016002: Processing weld deployment MyService.war
04:50:28,278 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016005: Starting Services for CDI deployment: MyService.war
04:50:28,285 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016008: Starting weld service for deployment MyService.war
04:50:28,318 WARN  [org.jboss.weld.Event] (MSC service thread 1-2) WELD-000411: Observer method [BackedAnnotatedMethod] com.sun.jersey.server.impl.cdi.CDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
04:50:28,622 INFO  [com.sun.jersey.api.core.PackagesResourceConfig] (MSC service thread 1-2) Scanning for root resource and provider classes in the packages:
  org.rox.webservice
04:50:28,641 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./MyService: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./MyService: 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(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_05]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_05]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_05]
Caused by: com.sun.jersey.core.spi.scanning.ScannerException: The URI scheme vfs of the URI vfs:/content/MyService.war/WEB-INF/classes/org/rox/webservice is not supported. Package scanning deployment is not supported for such URIs.
Try using a different deployment mechanism such as explicitly declaring root resource and provider classes using an extension of javax.ws.rs.core.Application
    at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:225)
    at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139)

web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <servlet>
        <servlet-name>MyWebService</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>org.rox.webservice</param-value>
       </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyWebService</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <display-name>MyWebService</display-name>
</web-app>

pom.xml

<?xml version="1.0"?>
<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>MyWebService</groupId>
    <artifactId>MyWebService</artifactId>
    <version>8.0.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>MyWebService</name>
    <description>MyWebService</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.wildfly.maven.plugin>1.0.1.Final</version.wildfly.maven.plugin>
        <version.compiler.plugin>3.1</version.compiler.plugin>
        <version.war.plugin>2.1.1</version.war.plugin>

        <!-- maven-compiler-plugin -->
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
    </properties>

    <dependencies>
        <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.8.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-server</artifactId>
                <version>1.8</version>
            </dependency> 
    </dependencies>

    <build>
        <!-- Set the name of the war, used as the context root when the app 
            is deployed -->
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>${version.war.plugin}</version>
                <configuration>
                    <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
                    <failOnMissingWebXml>true</failOnMissingWebXml>
                </configuration>
            </plugin>
            <!-- WildFly plugin to deploy war -->
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>${version.wildfly.maven.plugin}</version>
            </plugin>
            <!-- Compiler plugin enforces Java 1.6 compatibility and activates 
                annotation processors -->
              <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${version.compiler.plugin}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

【问题讨论】:

    标签: maven deployment wildfly wildfly-8


    【解决方案1】:

    看来你部署的不是WAR文件或者WAR目录,而是整个项目。注意服务器日志上的pom.xml,它不应该在那里。我会检查 standalone/deployments 以检查那里复制的内容。

    另外,尝试运行mvn package 并将文件手动复制到standalone/deployments/

    【讨论】:

    • 我试过mvn package并手动复制它。当我尝试来自 WildFly/JBoss 项目的 hello world 应用程序时它起作用了,但当我尝试使用我自己的项目时它不起作用。请看看我上面的编辑。
    • 这与最初报告的问题不同。如果你想在 Wildfly 服务器上使用 Jersey,你真的应该重新考虑,因为 Wildfly 已经附带了 JAX-RS 实现。尝试删除 serlet 和 servlet-mapping 类。您的 REST 端点应该可以在没有这些的情况下工作。
    【解决方案2】:

    尝试使用 wildfly maven 插件来部署您的应用,而不是手动将应用复制到部署文件夹。 不过,如果您想要或需要将您的应用复制到部署文件夹,请仅复制目标文件夹中的存档,而不是整个 maven 项目。

    通常,您应该更喜欢“基于 cli”的部署方法,而不是部署文件夹。 Wildfly maven 插件将在部署期间为您完成所有这些工作。

    【讨论】:

    • 我添加了 maven wildfly 插件,但它不起作用。请看我上面的编辑。
    【解决方案3】:

    我在你的 pom.xml 中找到了这个依赖:

    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-server</artifactId>
      <version>1.8</version>
    </dependency>
    

    我认为您不能使用 Jersey,因为 Wildfly 带有自己的 JAX-RS 实现 (Resteasy)。为什么要包含此依赖项?去掉试试,我觉得应该没问题。

    【讨论】:

      【解决方案4】:

      \standalone\deployments 中删除&lt;your project name&gt;.war 文件,然后重试。

      【讨论】:

        【解决方案5】:

        编辑: 在进行了更多挖掘之后,这在 Jersey 2.13 版本 https://jersey.java.net/release-notes/2.13.html 中得到了修复。如果您卡在 Jersey 1.x 上,请参阅下面的解决方法。

        在 JBoss 7 和 Wildfly 下的 Jersey 1.x 中使用包扫描存在问题。有一张针对泽西队的罚单,但已被关闭为“不重要,不会修复”:https://java.net/jira/browse/JERSEY-763

        这似乎非常无用,因为我发现的唯一解决方法已在该票证中列出,涉及在扩展 javax.ws.rs.core.Application 的自定义类中手动指定所有 Resources,并作为 init-param 传递给 Jersey servlet .

        我建议我们对工单发表评论,并询问为什么它不值得修复,因为对于大多数人来说,包扫描比手动指定资源更受欢迎。

        根据该票证中的详细信息,这是一个对我有用的示例:

        web.xml:

        <servlet>
            <servlet-name>com.sun.jersey.samples.helloworld.resources.MyApplication</servlet-name>
            <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
            <init-param>
                <param-name>javax.ws.rs.Application</param-name>
                <param-value>com.sun.jersey.samples.helloworld.resources.MyApplication</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <context-param>
            <param-name>resteasy.scan</param-name>
            <param-value>false</param-value>
        </context-param>
        <context-param>
            <param-name>resteasy.scan.providers</param-name>
            <param-value>false</param-value>
        </context-param>
        <context-param>
            <param-name>resteasy.scan.resources</param-name>
            <param-value>false</param-value>
        </context-param>
        

        com.sun.jersey.samples.helloworld.resources.MyApplication:

        package com.sun.jersey.samples.helloworld.resources;
        
        import java.util.HashSet;
        import java.util.Set;
        import javax.ws.rs.core.Application;
        
        public class MyApplication extends Application {
            @Override
            public Set<Class<?>> getClasses() {
                final Set<Class<?>> classes = new HashSet<Class<?>>();
                // Add your class resources here like below
                classes.add(HelloWorldResource.class);
                return classes;
            }
        }
        

        【讨论】:

          猜你喜欢
          • 2015-08-05
          • 2023-03-18
          • 2014-06-22
          • 1970-01-01
          • 2016-03-26
          • 2015-04-15
          • 1970-01-01
          • 2015-12-12
          • 1970-01-01
          相关资源
          最近更新 更多