How is the context path set in a Java web application?

I like to know how the context path is set in the java web application.
More precisely, in the case of the maven project, the context path is set from the pom.xml file?
Is the context path value a link anywhere in the web application, or is it just the name of the WAR file?
Is it possible that the WAR file name and context path are different?

+7
source share
3 answers

The context path is the name of the war file, despite the fact that the project is built through ant, maven, gradle or something else. If you want to change the context path of your application, the easiest way would be to change the name of the generated war. In maven this can be done using a plugin, here is an example:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <warName>kasnet-webapp</warName>
    </configuration>
</plugin>

Another way you can do this is to use a specific configuration for the application server that you are using, as shown here .

+6
source

Adding an answer for full details.

There are three ways to do this:

1. If you do not use Eclipse / MyEclipse to deploy the application to the application server -

You need to use the maven-war plugin, you can specify warName in the configuration section.

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <warName>customwarname</warName>
    </configuration>
</plugin>

2. Eclipse/MyEclipse -

eclipse eclipse, maven.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.10</version>
    <configuration>
        <wtpversion>2.0</wtpversion>
        <wtpContextName>customwarname</wtpContextName>
    </configuration>
</plugin>

eclipse.

   mvn eclipse:eclipse -Dwtpversion=2.0

Eclipse, , Properties- > Web, , .

, m2eclipse, .

3. : , , URL- .

+3

Eclipse/Maven/Wildfly, "jboss-web.xml" "WEB-INF", ;

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>MyContextName</context-root>
</jboss-web>
0

Source: https://habr.com/ru/post/1626363/


All Articles