如何从Eclipse在Jetty 8上运行Web Service Maven项目? [英] how to run a web service maven project on jetty 8 from eclipse?

查看:258
本文介绍了如何从Eclipse在Jetty 8上运行Web Service Maven项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个REST Web服务,该服务是我先前创建并部署在Tomcat7中的.我想按照建议部署在Jetty上.在上一个问题中,我创建了一个Maven项目,并在其中复制了文件并配置了依赖项,这样我就可以成功地从eclipse运行Maven安装.

I have a REST web service which I created previously and deployed in Tomcat7. I wanted to deploy it on Jetty, as advised in a previous question, I made a Maven project and copied my files there and configured the dependencies and I can run Maven install from eclipse successfully.

这是我在POM.xml中的build部分:

This is my build part in POM.xml:

 <build>
    <plugins>
        <plugin>
             <groupId>org.mortbay.jetty</groupId>
             <artifactId>maven-jetty-plugin</artifactId>
        </plugin>

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <dependentWarExcludes></dependentWarExcludes>
                <webappDirectory>
                    WebContent
                </webappDirectory>

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

我已按照此处的说明进行操作码头插件(我不确定是否需要).这里的问题是如何从eclipse中将我的maven项目部署在码头上,以便例如可以转到http:localhost:8080/myproject并查看我的项目是否正常工作?

I followed instructions here to use maven jetty plug-in (I am not sure if this is required). The question here is how can I deploy my maven project in jetty from eclipse so that i can go to http:localhost:8080/myproject for example and see my project working?

我以前在Tomcat上运行服务的方式是右键单击项目,然后单击运行方式->在服务器(在Eclipse服务器中配置)上运行

The way I used to run the service on Tomcat was by right click on the project and click on Run As -> Run on server (which is configured in eclipse servers)

我正在使用Eclipse Indigo,Maven 3和Jetty8.另外,我还使用jersey作为Web服务.

I am using eclipse Indigo, Maven 3 and jetty 8. Also I used jersey for the web service.

推荐答案

在这里,您要混合两种不同的东西:

Here, you are mixing two different things:

  1. 使用Eclipse服务器插件作为Eclipse的Tomcat插件运行Web应用程序.
  2. 使用Maven插件作为Jetty Maven插件运行Web应用程序.也有适用于Tomcat的Maven插件.

话虽如此,请看一下答案,其中描述了如何配置Eclipse以运行Maven插件(可能会有所不同,具体取决于Eclipse版本,但想法会类似)

Having said that, take a look to this answer where it is described how to configure Eclipse to run Maven plugins (it could change depending on Eclipse version but idea would be similar)

如果只想从Maven运行码头,只需使用以下命令行:

If you just want to run jetty from Maven, just use the following command line:

mvn jetty:run

但是,无论如何,我建议您在pom文件中指出Maven码头插件版本(如果您不这样做,Maven会警告您).

But, in any case, I recommend that you indicate the Maven jetty plugin version in the pom file (Maven will warn you if you don't).

已编辑2

首先,更新您的Jetty Maven插件版本:

First, update your jetty maven plugin version:

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.0.0.M2</version>
</plugin>

第二.您正在使用两个插件,一个用于构建war文件(maven-war-plugin),另一个用于在jetty上运行您的应用程序(jetty-maven-plugin).请记住,jetty认为您的项目具有标准的maven项目结构,这意味着它将在/src/main/webapp中查找您的Web应用程序内容,但看起来不在这里.在war插件配置中,您指定您的Web内容位于WebContent中,因此,请告诉jetty插件目录在那里,以及将其告知war插件:

Second. You are working with two plugins, one for building the war file (maven-war-plugin) and another one for running your application on jetty (jetty-maven-plugin). Take in mind that jetty thinks your project has a standard maven project structure, it means, it will look for your web app content in /src/main/webapp but it looks like is not here. In your war plugin configuration, you specify that your web content is in WebContent, so tell jetty plugin that directory is there, as well as you are telling it to war plugin:

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.0.0.M2</version>
    <configuration>
        <webAppSourceDirectory>/WebContent</webAppSourceDirectory>             
        <webXml>/over/here/web.xml</webXml>
        <jettyEnvXml>/src/over/here/jetty-env.xml</jettyEnvXml>
        <classesDirectory>/somewhere/else</classesDirectory>
    <configuration>
</plugin>

请参见文档.当然,最好使用标准的Maven项目结构,这样您就不必告诉码头事情在哪里.

See documentation. Of course, it is better to work with a standard maven project structure so you do not need to tell jetty where things are.

这篇关于如何从Eclipse在Jetty 8上运行Web Service Maven项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆