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>
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 am having maven web project with name XYZwebApp and i generated war inside that as ABCWebApp while running the project as (Right click -->Run As--> Run on Server)
it shows the XYZwebApp in the configured AddorRemove window
And also after running the application its opening the 404 page with the url http://localhost:9090/ABCWebApp/
But if i am changing the url as http://localhost:9090/XYZWebApp/ its working fine.
Above thing is happening in Jboss server in eclipse, i need application should be working fine with this url http://localhost:9090/ABCWebApp/
But the above problem is not happing when i start the server in cmd and pasting the war in webapps folder is working fine.
Confused by this issue, please help me why it is happening and how to resolve.
Give comments if you need more input.
i added path as ABCWebApp doesnt work and
i changed name as ABCWebApp doesnt work.
My pom.xml is
<artifactId>XYZwebApp</artifactId>
<packaging>war</packaging>
<name>ABCWebApp</name>
<build>
<finalName>ABCWebApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<path>/ABCWebApp</path>
</configuration>
</plugin>
</plugins>
</build>
have you configured the context root correctly? Eclipse>WarProject>Properties>Web>Context Root
Double-click on the tomcat server on which you are deploying you application in Servers view, go to modules tab and check the Path for the application is correct as you need. If it is not then select and edit the path, save it and re-run the application (Right click -->Run As--> Run on Server).
Edit 1:
Modules tab and path to edit can be found highlighted in below image,
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 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>