【问题标题】:Running jetty server in multi module project在多模块项目中运行码头服务器
【发布时间】:2016-01-24 05:59:46
【问题描述】:

我已经为这个问题苦苦挣扎了 5 个小时——我有一个多模块项目,并且在其中一个模块(RestManagement)中我想做 REST API。不幸的是,每当我尝试运行它时,我得到的都是一堆错误。

在 RestManagement 模块中我有文件 HelloResource

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

@Path("/hello")
public class HelloResource {

    @GET @Path("/{name}") @Produces("text/plain")
    public String getMsg(@PathParam("name") String name) {

        return "hello: " + name;
    }
}

我的应用程序

public class MyApplication extends ResourceConfig {
    public MyApplication() {
        register(HelloResource.class);
    }
}

我的模块 POM 是

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>oceniarka</artifactId>
        <groupId>oceniarka</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>RestManagement</artifactId>

    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <layout>default</layout>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
    </repositories>



    <dependencies>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>2.16</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>2.16</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.19</version>
        </dependency>

        <dependency>
            <groupId>oceniarka</groupId>
            <artifactId>DataManagament</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

    </dependencies>


    <build>
        <finalName>RestManagement</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.3.v20140905</version>

            </plugin>
        </plugins>
    </build>


</project>

当我想做 mvn jetty:run 虽然我得到错误

No plugin found for prefix 'jetty' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories

即使我的模块 POM 中有它。我还尝试使用 mvn -am -pl RestManagement jetty:run 仅运行此模块:运行我得到相同的错误。 我试图把这个插件放到主 POM 中,但后来又出现了另一个错误。除了我在这里描述的场景之外,我确实尝试了五十种不同的方法来让它发挥作用,但它们都没有帮助,现在我非常生气和绝望 希望有人能帮忙! 提前致谢

【问题讨论】:

  • 你在 settings.xml 中的存储库

标签: java maven jersey jetty


【解决方案1】:

实际上我已经想通了,所以我会为任何可能寻找它的人发布答案。 首先,您的码头的构建插件应该在您的 REST 模块 POM 中,其次您应该执行命令 mvn clean、mvn install 和 mvn dependency:go-offline 这样您的 maven 会将所有其他模块下载到本地 repo(我不是确定你是否需要所有三个命令,但我想为了确定而执行所有命令并没有什么坏处)。然后,您应该从模块目录中的控制台(在我的情况下为 mvn jetty:run)运行所需的 maven 命令。 我不确定当我这样做时它不起作用

mvn -am -pl RestManagement jetty:run

但是这种方式对我有用。如果您遇到类似问题,我希望它对您有用

【讨论】:

    猜你喜欢
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    相关资源
    最近更新 更多