Simon F
Simon F

Reputation: 13

Jetty | Deploy war and static content

I am trying to deploy a war file (containing my java backend) and some static content (containing a compiled angular project) to a jetty server.

First of all it works but I want to improve the deployment. Currently my war file is deployed from the target directory of the webapp-project. The static content (angular project) is deployed from the src/main/webapp directory where the WEB-INF Folder containing the web.xml is located.

But it would be nice if I could deploy both (war file and static content) from the target folder.

My current configuration in my pom.xml:

<project xmlns="..." xmlns:xsi="..."
xsi:schemaLocation="...">
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>SurefireAuswerterBackend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-jetty-http</artifactId>
        <version>2.25.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-jetty-servlet</artifactId>
        <version>2.25.1</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.20.v20161216</version>
            <dependencies>
                <dependency>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-io</artifactId>
                    <version>9.2.20.v20161216</version>
                </dependency>
            </dependencies>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <war>${project.basedir}/target/surefire-auswerter.war</war>
                <stopKey>alpha</stopKey>
                <stopPort>4445</stopPort>
                <httpConnector>
                    <port>4444</port>
                </httpConnector>
                <webAppSourceDirectory>${project.basedir}/target/surefire-auswerter</webAppSourceDirectory>
                <webAppConfig>
                    <contextPath>/surefire-auswerter</contextPath>
                </webAppConfig>
            </configuration>
        </plugin>
    </plugins>
</build>

I have removed some configuration which is not important.

I have tried a lot of e.g. to set the WebAppSourceDirectory but nothing worked. Is there any solution which is always used or which do what I want?

PS: Please excuse my language - I am not very practiced in English yet. Furthermore, this is my first question on StackOverlow, so please excuse me if I write something too vague.

I'm open to criticism.

Thank you for your efforts and answers!

Upvotes: 0

Views: 867

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49462

Use the jetty:run-war goal instead, that's why it exists.

https://www.eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html#running-assembled-webapp-as-war

Also, Jetty 9.2.x is now deprecated, please upgrade to Jetty 9.4.x.

Upvotes: 1

Related Questions