2

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.

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> 

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?

EDIT:

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)

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

Community
  • 1
  • 1
Sami
  • 7,337
  • 16
  • 39
  • 68

1 Answers1

2

Here, you are mixing two different things:

  1. Run your Web application using a Eclipse server plugin as Tomcat plugin for Eclipse.
  2. Run your Web application using a Maven plugin as Jetty Maven plugin. There are also Maven plugins for Tomcat.

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)

Edited:

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

mvn jetty:run

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).

Edited 2

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>

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>

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.

Community
  • 1
  • 1
jddsantaella
  • 3,592
  • 1
  • 19
  • 38
  • sorry for the confusion, but I want the second (running the web app using maven jetty plugin) – Sami Jul 30 '12 at 11:47
  • So, you can do it directly from commando line or configuring Eclpise for do it that as described the link in my answer. – jddsantaella Jul 30 '12 at 11:52
  • I was trying it, but i got this error: Failed to execute goal org.mortbay.jetty:maven-jetty-plugin:6.1.26:run (default-cli) on project *****service: Webapp source directory C:\Java\eclipse-workspace\*****service\src\main\webapp does not exist. //// where **** hides the project name – Sami Jul 30 '12 at 12:05
  • what should be in the base directory of the run configuration? .. I used this : ${workspace_loc:/*****service}. (the project directory). Is this what should be there? – Sami Jul 30 '12 at 12:10
  • There, it should be your web content. I've edited my answer again in order to provide you more information. – jddsantaella Jul 30 '12 at 13:38