Akhil K Nambiar
Akhil K Nambiar

Reputation: 3975

Maven Web project via Eclipse

I created a DynamicWebProject in Eclipse then pressed the RUN button. The browser window opened after building the project. That works exactly as I wanted. Now I create a Maven project with webapps archtype. There is a default index.jsp file. Now I press the run button. Nothing happened. Then I created a run configuration and added the Tomcat server. Now the server starts but the browser doesn't start neither is my app deployed. What changes should I make so that it will like the dynamic web project case? No mvn deploy or packaging to WAR archieve and extract.

Upvotes: 0

Views: 1798

Answers (3)

TonyQ
TonyQ

Reputation: 667

Use Eclipse Run-Jetty-Run to run your project , just one click without any configuration!

Reference http://code.google.com/p/run-jetty-run/

Upvotes: 0

proko
proko

Reputation: 1210

I tried to sum up the steps needed to deploy a simple maven web app on a tomcat server within eclipse (tested with eclipse indigo).

1.) Get eclipse
2.) Install two plugins via eclipse marketplace (Maven integration for eclipse and Maven integration for eclipse WTP, also known as m2eclipse and m2eclipse extras)
3.) Download tomcat server
4.) Open the Eclipse - Server view and add the tomcat server
5.) create a new maven project (with archtype web-app)
6.) enhance your pom with the following code:

<dependencies>
    <!-- ... something like junit could already be in dependencies -->
    <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
           <scope>provided</scope>
    </dependency>
    <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
    </dependency>
</dependencies>

7.) right click on the tomcat server (eclipse - server view) and add the new maven project
8.) start the tomcat
9.) open a browser and type http://localhost:8080/APPNAME

Following the steps above, the maven webapp should be deployed to the tomcat automatically. No need of 'mvn deploy' or packaging to WAR to drop into the tomcat manually.

Double-clicking on the server configuration opens the server properties. There you can find the deploy path for the webapps.

Upvotes: 2

Eugene
Eugene

Reputation: 121048

Honestly I do not understand what you are trying to do (or did), but, if you even mention maven and eclipse, then you should be using m2eclipse - t Then you should dig into the maven documentation - there are tons of examples, one of them probably http://mojo.codehaus.org/tomcat-maven-plugin/run-mojo.html

of how to set up tomcat through maven. For the development I would suggest switching to jetty - it is more convenient and easier to deploy (actually it's auto deploying):

small portion of how it will look in pom.xml

<!-- Normally, testing a web application involves compiling Java sources, 
                    creating a WAR and deploying it to a web container. Using the Jetty Plugin 
                    enables you to quickly test your web application by skipping the last two 
                    steps. By default the Jetty Plugin scans target/classes for any changes in 
                    your Java sources and src/main/webapp for changes to your web sources. The 
                    Jetty Plugin will automatically reload the modified classes and web sources -->
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>${jetty.port}</port>
                            <maxIdleTime>60000</maxIdleTime>
                            <Host>localhost</Host>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>

I am sure something similar could be achieved with tomcat.

The rest of the things you are asking, I think, are way too blurry to be answered, so please be a bit more specific.

Upvotes: 1

Related Questions