簡體   English   中英

在多模塊項目中運行碼頭服務器

[英]Running jetty server in multi module project

我已經在這個問題上苦苦掙扎了大約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,但隨后又遇到另一個錯誤。 除了我在這里描述的場景之外,我確實嘗試了五十種不同的方法來使它起作用,但是它們都沒有幫助,現在我非常生氣和絕望,希望有人可以幫助! 提前致謝

其實我已經弄清楚了,所以我將答案發布給任何可能會尋找它的人。 首先,您的碼頭的構建插件應該在REST模塊POM中,其次,您應該執行命令mvn clean,mvn install和mvndependency:go-offline,以便您的maven會將所有其他模塊下載到本地存儲庫中(我不是確保您是否需要全部三個命令,但是我敢肯定,執行所有命令並沒有什么害處)。 然后,您應該在模塊目錄中的控制台上運行所需的maven命令(在我的情況下為mvn jetty:run)。 我不太確定我什么時候不起作用

mvn -am -pl RestManagement jetty:run

但是這樣對我有用。 如果您遇到類似的問題,希望它對您有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM