maven-jetty-plugin does not run application on contextPath - maven

maven-jetty-plugin is always running application on default context path ('/'). I tried running by setting contextpath property to 'test' but it does not work. http://localhost:8080/test is not accessible. It still runs on default context path.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>9.1.0.M0</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/test</contextPath>
</webApp>
<connectors>
<!-- work around file locking on windows -->
<connector implementation="org.mortbay.jetty.bio.SocketConnector">
<port>8080</port><!-- this connector defaults to 1300 for some reason -->
</connector>
</connectors>
</configuration>
</plugin>

using only
<contextPath>/test</contextPath>
instead of
<webApp>
<contextPath>/test</contextPath>
</webApp>
worked for me

Related

Cargo:run If you specify a containerId, you also need to specify a containerUrl

I am trying to run tomcat though cargo. Tomcat is already installed. cargo:deploy is working fine but when I try cargo:run I get the following error
If you specify a containerId, you also need to specify a containerUrl.
If I specify a containerURL I get the following error
[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-
plugin:1.4.13:run (default-cli) on project ctm: Unable to parse configuration
of mojo org.codehaus.cargo:cargo-maven2-plugin:1.4.13:run for parameter
containerURL: Cannot find 'containerURL' in class org.codehaus.cargo.maven2.configuration.Container
...
This is my Maven config
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.13</version>
<configuration>
<container>
<type>existing</type>
<containerId>${cargo.maven.containerId}</containerId>
<home>${container.home}</home>
</container>
<configuration>
<type>existing</type>
<home>${container.home}</home>
</configuration>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
<properties>
<context>example</context>
</properties>
</deployable>
</deployables>
</configuration>
<executions>
<execution>
<id>run</id>
<configuration>
<configuration>
<type>existing</type>
</configuration>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
this is my profile
<profile>
<id>developer-properties</id>
<properties>
<cargo.maven.containerId>tomcat7x</cargo.maven.containerId>
<container.home>C:/apache-tomcat-7.0.35</container.home>
</properties>
</profile>
According to cargo documentation; type "existing" should use an existing container installation. I don't think I need containerURL unless the type is "standalone". I don't understand why I'm getting the containerURL error.
Documentation on type is here: https://codehaus-cargo.github.io/cargo/Existing+Local+Configuration.html
I think the documentation is unclear. I think cargo:run always uses a standalone local configuration, hence the description
If the plugin configuration defines a container with a standalone
local configuration, it will create the configuration.
So it's probably ignoring your existing local configuration.

Set context root for spring annotation based web app

How can set the context root for a annotation based spring web app? Sample application found in following link,
https://github.com/bkielczewski/example-spring-mvc-initializer
In browser I can access it as,
http://localhost:8080/
I want to change it as,
http://localhost:8080/spring
Thanks,
Charith
Update your pom.xml to include web-app configuration. See below
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.6.v20130930</version>
<configuration>
<webApp>
<contextPath>/spring</contextPath>
</webApp>
<httpConnector>
<port>8080</port>
<host>localhost</host>
</httpConnector>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>

"Too many open files" exception while running mvn org.mortbay.jetty:jetty-maven-plugin:run

In one of my project , I have used Lift 2.5 M4 and Scala 2.10.0 . In this project , I am using Jetty 8.1.10.v20130312 .
But while running project through mvn jetty , I am getting unexpected exception .
I have configured jetty plugin in pom.xml in below way :
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.10.v20130312</version>
<configuration>
<systemProperties>
<systemProperty>
<name>org.apache.cocoon.log4j.loglevel</name>
<value>WARN</value>
</systemProperty>
</systemProperties>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>9090</port>
<maxIdleTime>30000</maxIdleTime>
</connector>
</connectors>
<webApp>
<contextPath>/</contextPath>
</webApp>
<scanIntervalSeconds>0</scanIntervalSeconds>
<stopKey>stop</stopKey>
<stopPort>9999</stopPort>
</configuration>
</plugin>
I am getting below exception while running command :- mvn org.mortbay.jetty:jetty-maven-plugin:run
2013-04-24 06:49:39.216:WARN:oeja.AnnotationParser:EXCEPTION
java.io.FileNotFoundException: /home/ayush/scala-lift/knolgame/target/classes/com/knolgame/lib/TransactionStatus$$anonfun$find$1.class (Too many open files)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)
at org.eclipse.jetty.util.resource.FileResource.getInputStream(FileResource.java:286)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:754)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:747)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:747)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:747)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:747)
But When I am using jetty 6.1.25 , It works fine .
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.25</version>
<configuration>
<systemProperties>
<systemProperty>
<name>org.apache.cocoon.log4j.loglevel</name>
<value>WARN</value>
</systemProperty>
</systemProperties>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9090</port>
<maxIdleTime>30000</maxIdleTime>
</connector>
</connectors>
<contextPath>/</contextPath>
<scanIntervalSeconds>0</scanIntervalSeconds>
<stopKey>stop</stopKey>
<stopPort>9999</stopPort>
</configuration>
</plugin>
Can anyone help me to resolve this ? I have to use latest Lift , Scala and jetty version in my application .
Thanks in advance .
Regards,
Ayush
"Too many open files" usually means that your java process is not allowed to open any more file descriptors.
However if this happens at startup of jetty w/o any big amount of connections opened something weird is going on.
First of all you can check the configured soft limit of allowed open files (or filedescriptors) by executing: $ ulimit -a on your commandline.
Please paste the results to here if you need further access.
Then you can use tools like lsof to check what files your java process failing with the given exception above has opened at that time. $ lsof -p <pid> where pid is the processId of your java/jetty process should give you some hints.
If your soft limit is just too small try raising it by following one of the many tutorials found in the internet like: http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/ (first result I found) to raise the limit to something appropriate. What value will fit your application mainly depends on the amount of concurrent open connections you'll serve.

jetty-maven-plugin setting buffers sizes

Returning to jetty-maven-plugin I've trouble to set buffers size.
My use-case imply file upload (usual size is ~700Ko).
Because the upload is too big for jetty-maven-plugin default configuration I get Http response with error status code 413 (request too large)
I tryied using plugin configuration :
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven.version}</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
<requestHeaderSize>8192</requestHeaderSize>
<requestBufferSize>2097152</requestBufferSize>
</connector>
</connectors>
</configuration>
</plugin>
Then I tried to use jetty-maven-plugin with a jetty.xml file
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven.version}</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<jettyConfig>${basedir}/src/main/config/jetty/jetty.xml</jettyConfig>
</configuration>
</plugin>
The jetty.xml is below:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="requestBufferSize">2097152</Set>
</New>
</Arg>
</Call>
</Configure>
Nothing works.
Could someone hand me the correct configuration please?
I'm not sure whether this fixes the problem in your use case, but you could try adding the following to your <configuration> section of the maven-jetty-plugin:
<systemProperties>
<systemProperty>
<name>org.eclipse.jetty.server.Request.maxFormContentSize</name>
<value>-1</value> <!-- or any other value -1 is for max -->
</systemProperty>
<systemProperties>
as mentioned by jesse mcconnell the property was renamed in jetty 7/8 to org.eclipse.jetty.server.Request.maxFormContentSize.
For jetty 6 for me org.mortbay.jetty.Request.maxFormContentSize is working.
change your pom as per this and add this two xml file into your project. I hope, it will work for you.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<contextPath>/random-api</contextPath>
<scanIntervalSeconds>5</scanIntervalSeconds>
<jettyXml>jetty.xml,jetty-http.xml</jettyXml>
</configuration>
</plugin>
===============jetty.xml and jetty-http.xml=================
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-tools/xwiki-platform-tool-jetty/xwiki-platform-tool-jetty-resources/src/main/resources/jetty/etc/jetty.xml
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-tools/xwiki-platform-tool-jetty/xwiki-platform-tool-jetty-resources/src/main/resources/jetty/etc/jetty-http.xml
After a pause (lunch) I grabed the code of the web-app I was supposed to test.
There was a redundant limitation into its "internal" configuration (use an upload agent with it's own size limit).
In fact the two configuration proposed for jetty are working (now that web-app doesn't have any redundant limitation)

Configuration of the maven jetty (version 8.1) plugin for jax-ws webservices

I've managed to configure the maven jetty plugin to successfully deploy a jax-ws war with spring and an assortment of other libraries. However despite the successful deployment I'm always obtaining HTTP ERROR 404 Problem accessing /tstsrv Reason: not found.
The relevant section of my POM file bellow. I've commented a lot of configurations bellow that I have tried without success namely the jetty-jaxws2spi spi which I don't know quite how to configure it.
<build>
<finalName>tstsrv</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-jaxws2spi</artifactId>
<version>7.0.1.v20091125</version>
</dependency -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.6</version>
</dependency>
</dependencies>
<configuration>
<war>${basedir}/target/tstsrv.war<!-- ${basedir}/target/${project.artifactId}-${project.version}.${project.packaging}--></war>
<webApp>
<extraClasspath>${basedir}/src/main/custom/.</extraClasspath>
<contextPath>/tstsrv</contextPath>
<jettyEnvXml>${basedir}/src/test/resources/jetty-env.xml</jettyEnvXml>
</webApp>
<!-- systemProperties>
<systemProperty>
<name>com.sun.net.httpserver.HttpServerProvider</name>
<value>org.eclipse.jetty.jaxws2spi.JettyHttpServerProvider</value>
</systemProperty>
</systemProperties -->
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>9090</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<loginServices>
<loginService implementation="org.eclipse.jetty.security.HashLoginService">
<name>myrealm</name>
<config>${basedir}/src/test/resources/jetty-realm.properties</config>
</loginService>
</loginServices>
<requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
<filename>target/tmp/yyyy_mm_dd.request.log</filename>
<retainDays>90</retainDays>
<append>true</append>
<extended>false</extended>
<logTimeZone>GMT</logTimeZone>
</requestLog>
</configuration>
</plugin>
</plugins>
My Spring configuration is not using com.sun.xml.ws.transport.http.servlet.WSSpringServlet. I'm extending SpringBeanAutowiringSupport. I think this is relevant because I was able to make this work but only with the WSSpringServlet. I've used an example in this blog and that worked.
However that solution is not a option since I'm using weblogic in production and this implies code changes
Thnks for any help.
I was able to resolve this issue by making different configurations controlled by maven profiles. One with a WSSpringServlet for testing and the original one without it.
Tnks to commenters for the time taken to respond to this issue.

Resources