I am using Maven with Jetty / Tomcat. My pom.xml declares the ID of my application as <artifactId>webapp</artifactId>. Consequently, all my webapp source is located in src/main/java/webapp. Now, whenever I run any of the webserver, my URL looks like this:
http://localhost:8080/webapp/index.html
and I haven't found a clue that tells me how to get rid of the application or dir name and make the URL look like this:
http://localhost:8080/index.html
Any hints?
Couple of ways you could do this:
In Tomcat, rename the webapp.war to ROOT.war (note the capitalization)
Configure Apache on top of that and create a rewrite rule for pointing root to correct webapp.
Use Jetty's contextPath
Assuming you mean using the jetty:run and tomcat:run mojos (if not, please specify what you mean):
In Jetty, use the contextPath argument:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<!-- version omitted -->
<configuration>
<contextPath>/</contextPath>
<!-- other config -->
</configuration>
</plugin>
In Tomcat it's the path argument
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<!-- Version omitted -->
<configuration>
<path>/</path>
<!-- Other configuration -->
</configuration>
</plugin>
Related
I have just set up a basic Jetty project named music-store-api. To access my project through Jetty I would go to http://localhost:8090/music-store-api/hello-world. I am wondering how I would remove the music-store-api part from the URL so it becomes http://localhost:8090/hello-world?
Change the context path to root, aka "/".
Depending on how you have your music app deployed, there's a few different ways to accomplish this.
Since you are using jetty-maven-plugin and it's jetty:run goal, you'll need to edit your pom.xml.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.31.v20200723</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/</contextPath> <!-- this line is the important one -->
</webApp>
</configuration>
</plugin>
From: https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#configuring-your-webapp
I followed the instructions tp modify the contextPath on https://www.eclipse.org/jetty/documentation/current/configuring-specific-webapp-deployment.html
I hava a maven project, pom.xml contains tomcat plugin.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
I've downloaded Tomcat 7, so I've got Tomcat directory (apache-tomcat-7.0.56). I tried three goals to run my project:
tomcat7:run, tomcat7:run-war, tomcat7:run-war-only
My application is running at http://localhost:8080/projectname, if I run tomcat7:run-war, projectname-0.0.1-SNAPSHOT.war appears in the /target directory of my project.
I want to run my application at http://localhost:8080/.
I know this question was asked before, but unfortunately those solutions didn't help me.
I tried both methods from the first answer of this.
First method didn't work for me, after renaming war nothing changed, tomcat7:run-war-only requires war with name like projectname-0.0.1-SNAPSHOT.war.
The second method changed nothing (I tried both
<Context path="" docBase="projectname-0.0.1-SNAPSHOT" debug="0" reloadable="true"></Context>
and
<Context path="" docBase="projectname" debug="0" reloadable="true"></Context>)
I have also looked throw this, but I don't have <catalina_home>/conf/Catalina/localhost/ directory in my Tomcat directory.
Have you tried changing the context path by setting it in the configuration section of the Maven plugin?
FYI: Find the current version of the plugin here
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
I am using tomee and it works for me.
Add the context tag to the pom file as follows:-
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
..
<context>ROOT<context>
..
</configuration>
</plugin>
I am developing a Java web application, using a multi-module maven project. The project setup is the following:
pom.xml Main maven project, that includes the following modules:
persistence: Entity classes and DAOs
business: Service definition and implementation
webapp: Apache wicket web application
The dependency hierarchy is the following: webapp depends on business, which depends on persistence.
I am also using the Jetty Maven Plugin to run the web application locally using mvn -pl webapp jetty:run inside the directory with the main pom.xml. When developing the application, When making code changes, I want the jetty server to restart and reload the modified code files automatically. This works fine when I am modifying files inside the webapp module, but does not work when I am modifying a file inside another module, such persistence or business.
The Maven Jetty Plugin is configured inside webapp/pom.xml as follows:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.2.v20140723</version>
<configuration>
<reload>automatic</reload>
<scanIntervalSeconds>1</scanIntervalSeconds>
<webApp>
<extraClasspath>../business/target/classes/;../persistence/target/classes/</extraClasspath>
</webApp>
<scanTargets>
<scanTarget>../business/target/classes</scanTarget>
<scanTarget>../persistence/target/classes</scanTarget>
</scanTargets>
</plugin>
I followed the instructions of this answer. The <scanTarget> tags work fine, since jetty gets restarted when I modify a file inside business or persistence. However, the <extraClasspath> does not work since the modified files are not loaded by jetty. The linked answer uses the <webAppConfig> tag. However, I am using the <webApp> tag as specified in the documentation of the plugin (I also tried the old <webAppConfig> tag, which lead to the same results).
My question is: How to configure the Jetty Maven Plugin for a multi-module project, such that it reloads modified files from other modules?
To force the reload anytime a submodule is changed you can use the following options
1 - Static module names and scan targets
You can define as scan targets the target directory for each module
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.plugin.version}</version>
<configuration>
<scanIntervalSeconds>${jetty.scanInterval}</scanIntervalSeconds>
<scanTargets>
<scanTarget>module-name/target/classes</scanTarget>
<scanTarget>module-name2/target/classes</scanTarget>
</scanTargets>
</configuration>
</plugin>
2 - Dinamic module names and scan targets (recommended)
This uses RegEx to find the compilation target for other modules, on the following example, we are reloading the application everytime a class is compiled on any module
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.plugin.version}</version>
<configuration>
<scanIntervalSeconds>${jetty.scanInterval}</scanIntervalSeconds>
<scanTargetPatterns>
<scanTargetPattern>
<directory>${project.basedir}</directory>
<includes>
<include>**/target/classes/**/*.class</include>
</includes>
</scanTargetPattern>
</scanTargetPatterns>
</configuration>
</plugin>
Using trial and error, I found a solution. The problem is that jetty is executed using from the parent pom using
mvn -pl webapp jetty:run
The command is called from the directory of the main pom, thus jetty cannot resolve the relative paths inside the extraClasspath correctly. When executing the jetty:run goal inside the webapp directory, all modified classes are loaded correctly.
I assume the scanTargets are working correctly even when using mvn -pl webapp jetty:run, because the relative paths get resolved during the execution of the plugin (with the correct working directory). Jetty outputs the scan targets on startup:
[INFO] Added extra scan target:C:\PathToProject\business\target\classes
[INFO] Added extra scan target:C:\PathToProject\persistence\target\classes
However, the <extraClasspath>property is part of the <webApp> property, which is an instance of the org.eclipse.jetty.webapp.WebAppContext class. I assume that this instance is passed to jetty directly and that the extraClasspath property is accessed by jetty when it is already started.
The following configuration works for me
<!-- To launch embded jetty server -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.4.2.v20110526</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<webAppConfig>
<contextPath>/${project.name}</contextPath>
<extraClasspath>target/classes;../services/target/classes;../util/target/classes</extraClasspath>
</webAppConfig>
<scanTargets>
<scanTarget>target/classes</scanTarget>
<scanTarget>../services/target/classes</scanTarget>
<scanTarget>../util/target/classes</scanTarget>
</scanTargets>
</configuration>
</plugin>
I'm using maven and jetty for my web application. I give the command mvn jetty:run to run the maven/jetty which also will load my web application. But the path I get to use to access is http://localhost:8080/filename.jsp while I want it to be http://localhost:8080/myappname/filename.jsp
How to get this done ? Please let me know if I've to post specific files from my web app for you to be able to solve this.
I found other way around at Remove application name after localhost in jetty
From these docs: http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-run-goal
I think you just need to configure the contextPath in your pom.xml:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/test</contextPath>
</webApp>
</configuration>
</plugin>
I am using the cargo-maven2-plugin to start and stop a tomcat container from my maven build. I am able to get this working for my application including the deployment of extra jar files not included in the war. However, the war file I am deploying needs to have a directory/folder of groovy scripts included in the tomcat common classpath.
Is it possible to configure this cargo plugin to add a folder to the tomcat common classpath? Note, I am not looking to include a jar dependency into this classpath - just the folder of groovy scripts.
Edit: So far I have worked around this by copying in a new catalina.properties file that contains this folder. This works, but it is very container specific.
You can add a section to include file or directories, for instance
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<container>
...
</container>
<configuration>
<properties>
....
</properties>
<files>
<file>
<file>${basedir}/src/test/resources/alfresco-global.properties</file>
<todir>shared/classes</todir>
</file>
</files>
</configuration>
</configuration>
<executions>
...
</executions>
</plugin>
Further documentation in Maven 2 Plugin Reference Guide