Eclipse Jetty to Mortbay Jetty - heroku

I have eclipse jetty configured
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.0.v20131115</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
<webApp>
<contextPath>/websockets</contextPath>
</webApp>
</configuration>
</plugin>
Now I want to deploy it to Heroku. I change plugin to Mortbay Jetty
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>copy</goal></goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-runner</artifactId>
<version>7.5.4.v20111024</version>
<destFileName>jetty-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
The apps starts but the contextPath is not set to /websockets. How can i configure Mortbay Jetty's contextPath?

org.mortbay.jetty is for Jetty 6 and older. (DO NOT USE Jetty 6, it was EOL'd back in early 2010, and has no security or web updates since then)
(History Lesson)
Starting with Jetty 7, the project moved to the Eclipse Foundation, hence the name org.eclipse.jetty. Jetty 7 was the first version of Jetty to implement WebSocket drafts. The API evolved over the entire course of Jetty 7, and Jetty 8 and has decent (however partial/incomplete) support for WebSocket.
The WebSocket implementation (APIs and Protocol) was heavily refactored in Jetty 9 to support the finalized RFC-6455 (WebSocket Protocol), along with WebSocket extensions, and adding support for JSR-356 (Java WebSocket API).
You should also not mix versions of Jetty, you have Jetty runner at version 7.5.4, and jetty-maven-plugin at 9.1.0 - that will never work.
That being said, here's the 2 XML fragments of most use to you.
jetty-maven-plugin
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.2.v20140723</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
<webApp>
<contextPath>/websockets</contextPath>
</webApp>
</configuration>
</plugin>
jetty-runner
<artifactItem>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-runner</artifactId>
<version>9.2.2.v20140723</version>
<destFileName>jetty-runner.jar</destFileName>
</artifactItem>

Related

How to deploy a maven web project using Wildfly to Heroku?

I've built a Java EE 7 web app on Wildfly 10.
I'm trying to deploy it to Heroku, but I can't make the application work.
All I could do, so far, was to get Wildfly to work, but it seems to be running without my application.
I pushed the application using git:
git push heroku master
And it is running the unpack goal.
The Procfile:
web: target/wildfly-10.1.0.Final/bin/standalone.sh -Djboss.http.port=$PORT -b 0.0.0.0
The pom.xml
<!-- Commented to keep it simple -->
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${version.wildfly}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>target/wildfly-${version.wildfly}/standalone/deployments</outputDirectory>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
You need to add your ear/war into your wildfly deployment folder. To do that you need a separate plugin or something that will do that.
I want to try this too, so I will for example use this plugin under ear pom:
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<outputDirectory>../pathto/deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
You might need to use something else for a war.
To test it works just try compiling it and watch if your app is in the deployment folder.

How can I set spring profile on tomcat7-maven-plugin?

How can I set active spring profile o tomcat maven plugin? I want to get active profiles in runtime from Environment, but I' always getting empty array.
I tried to add this systemProperties in plugin configuration in pom.xml:
<JAVA_OPTS>-Dspring.profiles.active=local</JAVA_OPTS>
or
<name>spring.profiles.active</name>
<value>locale</value>
I try to add this in context.xml:
<environment name="spring.profiles.active" value="local" type="java.lang.String" override="false"/>
But still getting no active profile...
My env: Java 6, tomcat7-maven-plugin version 2.2, Netbeans 8.0.2, Spring 3.1.1.RELEASE.
My pom.xml tomcat plugin looks this:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- http port -->
<port>8084</port>
<contextFile>${basedir}/src/main/resources-local/context.xml</contextFile>
<systemProperties>
<JAVA_OPTS>-Dspring.profiles.active=local</JAVA_OPTS>
</systemProperties>
</configuration>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>run-war</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<dependencies>
Tomcat 7 Documentation shows a different syntax for System Properties like the one below. So try doing it this way:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<systemProperties>
<example.value.1>alpha</example.value.1>
<example.value.2>beta</example.value.2>
</systemProperties>
</configuration>
</plugin>

Jersey + Embedded Tomcat Minimal Maven Configuration

Could anyone provide simple configuration of Jersey and Embedded Tomcat in:
1) pom.xml
2) main method
I was trying to find it in google search, but they propose to use grizzly, glassfish and etc.
Thanks a lot.
I would go for webapp-runner to run the web app. It deploys the maven generated war from /target into a built in tomcat container. This is how java applications gets deployed on Heroku.
pom plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>7.0.34.1</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Dependency:
<dependency>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>7.0.34.1</version>
<scope>provided</scope>
</dependency>
to run the application after mvn clean package
java -jar target\dependency\webapp-runner.jar target\myapp.war

Jersey web-service runs fine with maven jetty:run but returns HTTP 404 with jetty-runner.jar

I have a single web-service implemented in Jersey (no container or anything else). When I run it through maven jetty:run, it works fine but I get the HTTP ERROR 404 when I use java -jar target/dependency/jetty-runner.jar --port 9090 target/*.war
I checked a similar post here but the solution does not work for me.
Here's how my pom.xml looks like:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.22</version>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9090</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<jetty-config>jetty.xml</jetty-config>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>copy</goal></goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-runner</artifactId>
<version>8.1.6.v20120903</version>
<destFileName>jetty-runner.jar</destFileName
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
I would appreciate any hint to solve my problem.
The problem was that the artifactId of my project was XXX. When I used mvn jetty:run, the url looked like this: localhost:9090/XXX/path/to/service. It did not return anything by calling: localhost:9090/path/to/service. However, when I change it to java -jar target/dependency/jetty-runner.jar --port 9090 target/*.war, the url should be localhost:9090/path/to/service and not the other one (localhost:9090/XXX/path/to/service).
I don't know what caused this setting, but at least I can get it to work.

Jetty daemon and useTestClasspath, what am I doing wrong?

Since I'm trying to set an embded container in my maven project I want to it run during the integration test phase. I have two problems with jetty that I can not manage to resolve :
<daemon>true</daemon> doesn't have the expected effect. The server is run but then it locks the build process (in fact it blocks the unit tests). So where am I supposed to place that configuration ?
The <useTestClasspath>true</useTestClasspath> is a mystery for me. I don't want to use the src/main/webapp/WEB-INF/lib to place the postgresql jar (which is called by jetty for the datasource (postegresql-driver)) because it would be embeded in the application and I don't want it to be in the war (client side). So I want to use <useTestClasspath>true</useTestClasspath> but when I place postgresql in the src/test/resources it doesn't find/recognize it. So, how am I supposed to use that property ?
Here is the complete plugin configuration :
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.9</version>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
<configuration>
<useTestClasspath>true</useTestClasspath>
<daemon>true</daemon>
<contextPath>agepro-prototype</contextPath>
<webApp>
${project.build.directory}/agepro-prototype.war
</webApp>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9091</port>
</connector>
</connectors>
<stopPort>9092</stopPort>
<stopKey>test</stopKey>
</configuration>
</plugin>
Thanks in advance for the help you could provide me. I must apologize for my grammar, because my english is quite bad.
Regards,
Depado
Not sure about your first question, but as for your second, specify the postgresql jar as provided scope in your main dependency block (this will prevent it from being bundled in the war), and add an additional dependency block in the jetty plugin definition (with compile scope), which will make the postgresql jar available at jetty runtime:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.9</version>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
<configuration>
<daemon>true</daemon>
<contextPath>agepro-prototype</contextPath>
<webApp>
${project.build.directory}/agepro-prototype.war
</webApp>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9091</port>
</connector>
</connectors>
<stopPort>9092</stopPort>
<stopKey>test</stopKey>
</configuration>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
<scope>provided</scope>
</dependency>
</dependencies>
I don't want to use the src/main/webapp/WEB-INF/lib to place the postgresql jar (which is called by jetty for the datasource (postegresql-driver)) because it would be embeded in the application and I don't want it to be in the war (client side). So I want to use true but when I place postgresql in the src/test/resources it doesn't find/recognize it
You shouldn't be placing jars in any folders (src/main/resources or src/main/webapp/WEB-INF/classes), they should all be defined as dependencies in your pom.
I also imagine the useTestClasspath is being ignored when you define the webApp configuration element, as the it's using the packaged war, which will not contain your test resources / classes
useTestClasspath/useTestScope are only available for jetty:run
This is why it doesn't work with jetty:run-war and other jetty:goals

Resources