How do I deploy multiple webapps WAR files into Jetty 8 with maven-jetty-plugin?
<contextHandlers>
<contextHandler implementation="org.mortbay.jetty.webapp.WebAppContext">
<war>${basedir}/dir/mywar.war</war>
<contextPath>/path</contextPath>
</contextHandler>
Seems to work only on older plugin versions.
Use the following snippet from a pom.xml. This is adapted from the Jetty server instructions, and although it's for Jetty7 it can easily be adapted for later versions.
pom.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<!-- Jetty 7.3+ requires Maven 3+ -->
<!-- Keep with Jetty 7.6.0 to avoid startup delays from Servlet API 3.0 -->
<version>7.6.0.RC1</version>
<configuration>
<stopKey>STOP</stopKey>
<stopPort>8009</stopPort>
<scanIntervalSeconds>10</scanIntervalSeconds>
<!-- Provide some JNDI resources (optional) -->
<jettyEnvXml>src/test/resources/jetty-jndi-config.xml</jettyEnvXml>
<!-- Register this application as a context -->
<webAppConfig>
<contextPath>/example</contextPath>
</webAppConfig>
<!-- Allow resources on the test classpath to be available -->
<useTestClasspath>true</useTestClasspath>
<!-- Add in any supporting application contexts (use dependencies section) -->
<contextHandlers>
<!-- Supporting WAR (note the use of a property entry for version, and see the dependency later - also Jetty 7 uses org.eclipse...) -->
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>
${settings.localRepository}/org/example/supporting-war/${supporting-war.version}/supporting-war-${supporting-war.version}.war
</war>
<contextPath>/supporting-war</contextPath>
</contextHandler>
</contextHandlers>
<connectors>
<!-- Later versions of Jetty don't require the Connector to be specified -->
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
<!-- SSL for localhost support -->
<connector implementation="org.mortbay.jetty.security.SslSocketConnector">
<port>8443</port>
<maxIdleTime>60000</maxIdleTime>
<!-- Provide a local key store for serving up SSL certificates -->
<keystore>src/test/resources/jetty-ssl.keystore</keystore>
<!-- Pick any password you like -->
<password>jetty6</password>
<keyPassword>jetty6</keyPassword>
</connector>
</connectors>
</configuration>
<dependencies>
<!-- This ensures that WAR files are downloaded from the repo -->
<!-- Example supporting WAR -->
<dependency>
<groupId>org.example</groupId>
<artifactId>supporting-war</artifactId>
<version>${supporting-war.version}</version>
<scope>compile</scope>
<type>war</type>
</dependency>
</dependencies>
</plugin>
I've left the SSL and JNDI configuration in there just in case anyone needs to see how they are configured. Obviously, they will need the supporting files. The SSL assumes that you've already created a suitable key store containing an SSL certificate for, say, localhost. The JNDI configuration file is as follows:
jetty-jndi-config.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="ExampleDB" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>java:jdbc/ExampleDB</Arg>
<Arg>
<New class="com.mchange.v2.c3p0.ComboPooledDataSource">
<Set name="driverClass">oracle.jdbc.driver.OracleDriver</Set>
<Set name="jdbcUrl">jdbc:oracle:thin:#//host:port/schema</Set>
<Set name="user">user</Set>
<Set name="password">password</Set>
<!-- Configure a simple connection test with timeout for subsequent queries -->
<Set name="preferredTestQuery">select 1 from dual</Set>
<Set name="checkoutTimeout">5000</Set>
</New>
</Arg>
</New>
</Configure>
This will allow a JNDI resource lookup using, for example, a Spring bean factory like this:
<bean id="exampleDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jdbc/ExampleDB"/>
<property name="resourceRef" value="true"/>
</bean>
Note that the C3P0 and Oracle references will introduce dependencies that are ostensibly local to your Jetty server, so should be placed in the <plugin><dependencies> section along with the WARs. They don't have to be in the main dependencies.
So now your Maven build will contain an embedded Jetty web server, configured to work with multiple WARs, all tied into the pom.xml version, providing both HTTP and HTTPS and backed with a pooled database connection. That's pretty much everything you need right out of the box for an integrated development environment.
Related
I'm using Maven and jetty plugin to local start my application.
And I have seen way that you could use placeholders in Jetty contextXML.
Here is part of my pom.xml (located in separate module) where I connected jetty plugin:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<stopKey>${test.jetty.stop-key}</stopKey>
<stopPort>${test.jetty.stop-port}</stopPort>
<webAppConfig>
<contextPath>/${test.contextPath}/*</contextPath>
</webAppConfig>
<httpConnector>
<port>${jetty.port}</port>
<host>${jetty.host}</host>
</httpConnector>
<contextXml>${project.basedir}/src/main/resources/jetty/${jetty.mode}-jetty.xml</contextXml>
</configuration>
<dependencies>
...
</dependencies>
</plugin>
Here is part of my stub-jetty.xml file:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
...
<New id="loggerCF" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jms/logger/connectionFactory/loggerCF</Arg>
<Arg>
<New class="org.apache.activemq.ActiveMQConnectionFactory">
<Arg>tcp://${active-mq.host}:${active-mq.port}</Arg>
</New>
</Arg>
</New>
</Configure>
Parameters "active-mq.host" and "active-mq.port" defined in main pom.xml file.
When I run I receive next exception:
Caused by: java.net.URISyntaxException: Illegal character in authority at index 6: tcp://${active-mq.host}:${active-mq.port}
at java.net.URI$Parser.fail (URI.java:2848)
...
So I understand that Jetty not understand that needed to change placeholders to values from Maven properties. How to fix this problem or what I could read about this?
You can't directly reference properties defined in Maven configurations. The desired behavior could be achieved with System Properties. You can set it up as a part of jetty-maven-plugin configuration, the required option is systemProperties or systemPropertiesFile.
Here is a rough example (please note that I haven't checked it):
<New class="org.apache.activemq.ActiveMQConnectionFactory">
<Arg>tcp://<SystemProperty name="active-mq.host"/>:<SystemProperty name="active-mq.port"/></Arg>
</New>
and pom:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<systemProperties>
<systemProperty>
<name>active-mq.host</name>
<value>${active-mq.host}</value>
</systemProperty>
<systemProperty>
<name>active-mq.port</name>
<value>${active-mq.port}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
Hi Spring Boot Experts -
I am trying to create a spring boot uber jar that needs to be deployed to a apache storm cluster. But, the catch is that Storm is expecting all the class files in the root of the jar while the packaged app files are under "BOOT-INF/classes" when packaged using the "spring-boot-maven-plugin".
Is there a way I can have my app classes packaged directly under the root instead of "BOOT-INF/classes"?
I tried using the "maven-assembly-plugin" with the "spring-boot-maven-plugin" as shown below which creates the Uber jar with all the class files from the dependency jars packaged at the root of the uber jar, but the app classes are still at BOOT-INF/classes.
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
</exclude>
</excludes>
<requiresUnpack>
<dependency>
<groupId>com.myorg</groupId>
<artifactId>my-app-artifact</artifactId> <!-- This does not help! :( -->
</dependency>
</requiresUnpack>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
So, for my future self or for anyone who is trying to find an answer for a similar question. Here are the different things that I realized during my research for this -
Storm wants an executable java jar file
Spring Boot provides a custom jar packaging. While it confirms with java jar packaging, Spring Boot loads the classes from the BOOT-INF/classes
So, to make a Spring Boot jar work on the storm cluster while behaving as Spring Boot - we would need to create a copy of all the classes from BOOT-INF/classes to the root of the jar file.
Is this possible? and the answer is yes.
Using the approach describe here, I was able to create a Spring Boot jar with the BOOT-INF/classes copied to the root of the Spring Boot jar. This approach requires ant build.xml, ivy settings and an ivy.xml as shown below. (disclaimer: config tested only till packaging on not on the storm cluster)
Since we are able to create a Spring Boot Jar hacked with classes at the root -
Should we do it? NO.
Here are the reasons -
Spring strongly advises not taking this approach to not end up with unwanted class overwrite and class versioning issues for classes with same names across jar files and with different versions.
Spring Boot Jar packaging is not a format intended for using as a dependency jar. Read the first line here. Hence for dependency use cases, you need to stick with your plain old java modules. Spring Boot is for more of standalone executables or for deployment on containers like tomcat.
Good luck!
build.xml
<project
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:spring-boot="antlib:org.springframework.boot.ant"
name="spring-boot-sample-ant"
default="build">
<description>
Sample ANT build script for a Spring Boot executable JAR project. Uses ivy for
dependency management and spring-boot-antlib for additional tasks. Run with
'$ ant -lib ivy-2.2.jar spring-boot-antlib.jar' (substitute the location of your
actual jars). Run with '$ java -jar target/*.jar'.
</description>
<property name="spring-boot.version" value="1.4.2.RELEASE" />
<property name="lib.dir" location="${basedir}/target/lib" />
<property name="start-class" value="com.my.main.class" />
<target name="resolve" description="--> retrieve dependencies with ivy">
<ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" />
</target>
<target name="classpaths" depends="resolve">
<path id="compile.classpath">
<fileset dir="${lib.dir}/compile" includes="*.jar" />
</path>
</target>
<target name="init" depends="classpaths">
<mkdir dir="target/classes" />
</target>
<target name="compile" depends="init" description="compile">
<javac srcdir="src/main/java" destdir="target/classes" classpathref="compile.classpath" />
</target>
<target name="clean" description="cleans all created files/dirs">
<delete dir="target" />
</target>
<target name="build" depends="compile">
<spring-boot:exejar destfile="target/${ant.project.name}-${spring-boot.version}.jar" classes="target/classes">
<spring-boot:lib>
<fileset dir="${lib.dir}/runtime" />
</spring-boot:lib>
</spring-boot:exejar>
</target>
<target name="unjar_dependencies" depends="compile">
<unzip dest="target/classes">
<fileset dir="${lib.dir}/compile">
<include name="my-app-common-0.1-SNAPSHOT.jar" />
</fileset>
</unzip>
</target>
<!-- Manual equivalent of the build target -->
<target name="manual" depends="compile, unjar_dependencies">
<jar destfile="target/manual/${ant.project.name}-${spring-boot.version}.jar" compress="false">
<mappedresources>
<fileset dir="target/classes" />
<globmapper from="*" to="BOOT-INF/classes/*"/>
</mappedresources>
<mappedresources> <!-- **** this mapped resources block does what I was looking for **** -->
<fileset dir="target/classes" />
<globmapper from="*" to="/*"/>
</mappedresources>
<mappedresources>
<fileset dir="src/main/resources" erroronmissingdir="false"/>
<globmapper from="*" to="BOOT-INF/classes/*"/>
</mappedresources>
<mappedresources>
<fileset dir="${lib.dir}/runtime" />
<globmapper from="*" to="BOOT-INF/lib/*"/>
</mappedresources>
<zipfileset src="${lib.dir}/loader/spring-boot-loader-jar-${spring-boot.version}.jar" />
<manifest>
<attribute name="Main-Class" value="org.springframework.boot.loader.JarLauncher" />
<attribute name="Start-Class" value="${start-class}" />
</manifest>
</jar>
</target>
</project>
ivysettings.xml
<ivysettings>
<settings defaultResolver="chain" />
<resolvers>
<chain name="chain" returnFirst="true">
<!-- NOTE: You should declare only repositories that you need here -->
<filesystem name="local" local="true" m2compatible="true">
<artifact pattern="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].[ext]" />
<ivy pattern="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom" />
</filesystem>
<ibiblio name="ibiblio" m2compatible="true" />
<ibiblio name="spring-milestones" m2compatible="true" root="http://repo.spring.io/release" />
<ibiblio name="spring-milestones" m2compatible="true" root="http://repo.spring.io/milestone" />
<ibiblio name="spring-snapshots" m2compatible="true" root="http://repo.spring.io/snapshot" />
</chain>
</resolvers>
</ivysettings>
ivy.xml
<ivy-module version="2.0">
<info organisation="org.springframework.boot" module="spring-boot-sample-ant" />
<configurations>
<conf name="compile" description="everything needed to compile this module" />
<conf name="runtime" extends="compile" description="everything needed to run this module" />
<conf name="loader" description="Spring Boot loader used when manually building an executable archive" />
</configurations>
<dependencies>
<dependency org="org.springframework.boot" name="spring-boot-starter" rev="${spring-boot.version}" conf="compile">
<exclude org="ch.qos.logback" name="logback-classic"/>
</dependency>
<dependency org="org.springframework.boot" name="spring-boot-loader" rev="${spring-boot.version}" conf="loader->default" />
<dependency org="org.apache.storm" name="storm-core" rev="1.0.2">
<exclude org="org.apache.logging.log4j" name="log4j-slf4j-impl"/>
<exclude org="org.apache.logging.log4j" name="log4j-core"/>
</dependency>
<dependency org="com.mycompany" name="app-common" rev="0.1-SNAPSHOT"/>
<dependency org="org.apache.storm" name="storm-kafka" rev="1.0.2"/>
<dependency org="org.apache.kafka" name="kafka_2.10" rev="0.10.1.0"/>
<dependency org="org.apache.kafka" name="kafka_2.10" rev="0.10.1.0"/>
<dependency org="org.apache.httpcomponents" name="httpcomponents-client" rev="4.5.2"/>
<dependency org="org.eclipse.paho" name="org.eclipse.paho.client.mqttv3" rev="1.1.0"/>
<dependency org="com.amazonaws" name="aws-java-sdk-s3" rev="1.11.53"/>
<dependency org="com.jcraft" name="jsch" rev="0.1.54"/>
<dependency org="io.netty" name="netty-handler" rev="3.7.0.Final"/>
</dependencies>
</ivy-module>
Is there a way I can have my app classes packaged directly under the root instead of "BOOT-INF/classes"?
Yes, you just need to use Spring Boot 1.3. Back to maven... in your pom.xml if you declare your parent like this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
then your classes (and other files) will be placed at the root level. This is the "old way" for spring boot.
In version 1.4 they changed the spring boot jar structure to use the BOOT-INF directory. So, if you use <version>1.4.1.RELEASE</version> for example, then your classes will be under BOOT-INF/classes. An undesirable side effect is that your configuration files (e.g., application.properties, application-myprofile.properties, etc.) will also be under BOOT-INF/classes, even though they are not Java classes.
I have a Maven ant plugin that bundles up a library of Ant tasks. One of them has a lot of CI tasks.
I have the plugin working and can hit the task by running
mvn -U ci:options
This brings up a menu for the different operations.
The issue i'm having is that I need to resolve dependencies in the pom before the task is executed.
From reading up I would have thought that I could add
<execution>
<goal>dependency:unpack-dependencies</goal>
</execution>
To the pluginMetaData xml file that defines the mojo, though this doesn't seem to do anything
ci.mojos.xml
<pluginMetadata xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/plugin-metadata-1.0.0.xsd">
<mojos>
<mojo>
<!-- target name to call in ant script -->
<call>run</call>
<!-- mojo goal name -->
<goal>options</goal>
<execution>
<goal>dependency:unpack-dependencies</goal>
</execution>
<parameters>
<parameter>
<name>artifactId</name>
<property>artifactId</property>
<required>true</required>
<readonly>true</readonly>
<type>java.lang.String</type>
<defaultValue>${project.artifactId}</defaultValue>
<description>Project Artifact Id</description>
</parameter>
....
ci.build.xml
<property name="project.home" location="."/>
<property name="target.dir" value="${project.home}/target"/>
<property name="build.dir" value="${target.dir}/build"/>
<property name="dependency.dir" value="${target.dir}/dependency"/>
<!-- Add contrib to the classpath -->
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<!-- Include ant utils from the shared resource -->
<include file="${dependency.dir}/shared_ant/build.xml"/>
<!-- Continuous Integration Options -->
<target name="run" description="Continuous Integration Options">
<ci.options/>
</target>
</project>
Any help greatly appreciated.
James
I am attempting to create some integration tests for my Spring web app using Jetty accessing a local HSQL database. The goal: run the tests using Selenium (or similar), mock/stub out all external systems, and setup a HSQL database to hit instead of our shared Oracle database. The tests are started during a maven build (the integration-test phase).
The database is initialized by Spring's "jdbc:initialize-database", and is registered as a JNDI datasource in Jetty.
After days of trying different configuration, I have finally gotten to the point where the database is created, initialized, and I think registered as a Jetty resource, but when the test cases run, it just hangs; I think because it is waiting for the database to become available.
Maven configuration
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.3.3</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<container>
<containerId>jetty7x</containerId>
<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
</dependency>
</dependencies>
</container>
<configuration>
<home>${project.build.directory}/cargo/configurations/jetty7x</home>
<properties>
<cargo.jetty.createContextXml>false</cargo.jetty.createContextXml>
<cargo.datasource.datasource>
cargo.datasource.url=jdbc:hsqldb:file:../../../myDB|
cargo.datasource.driver=org.hsqldb.jdbcDriver|
cargo.datasource.username=sa|
cargo.datasource.password=|
cargo.datasource.type=javax.sql.DataSource|
cargo.datasource.jndi=jdbc/myDataSource
</cargo.datasource.datasource>
</properties>
</configuration>
<deployables>
<deployable>
<location>target/myApp</location>
<properties>
<context>myApp</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
Spring configuration
<bean id="localDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="org.hsqldb.jdbcDriver"/>
<property name="jdbcUrl" value="jdbc:hsqldb:file:target/myDB"/>
<property name="user" value="sa"/>
<property name="password" value=""/>
</bean>
<jdbc:initialize-database data-source="mydataSource" ignore-failures="DROPS">
<jdbc:script location="classpath:/sql-scripts/schema/create-schema.sql"/>
<jdbc:script location="classpath:/sql-scripts/schema/create-tables.sql"/>
<jdbc:script location="classpath:/sql-scripts/testdata/data-load.sql"/>
</jdbc:initialize-database>
I am probably missing something, I tried to piece together the configuration through advice from many other posts. Any help would be appreciated.
The recommended method of using HSQLDB for tests, especially complex test setups, is running a Server.
Initially, you start an HSQLDB server using the shell, independently of your test setup. Use the Server property server.silent=false to see immediately the connections and statements on the console.
After some progress has been made, you can customize the server settings. See the Guide:
http://www.hsqldb.org/doc/2.0/guide/listeners-chapt.html
And a summary of different options for testing:
http://www.hsqldb.org/doc/2.0/guide/deployment-chapt.html#dec_app_dev_testing
You may need to use the MVCC transaction model. This reduces the locks and sometimes avoids the connections hanging as a result of on one waiting for the other to commit.
I have a problem with using ActiveMQ in a Spring project.
I am trying to integrate the ActiveMQ maven plugin into my project to use it in integration tests.
Here my configuration:
<?xml version="1.0" encoding="UTF-8"?> <!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--> <!-- START SNIPPET: example --> <beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:cam ="http://camel.apache.org/schema/spring"
xmlns:jetty ="http://mortbay.com/schemas/jetty/1.0"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd
http://mortbay.com/schemas/jetty/1.0
http://jetty.mortbay.org/jetty.xsd"> <!-- this location for the schema doesn't work, I dont know exactly where the schema is located
xmlns:jetty ="http://mortbay.com/schemas/jetty/1.0"
http://mortbay.com/schemas/jetty/1.0
http://jetty.mortbay.org/jetty.xsd -->
<!-- Allows us to use system properties as variables in this configuration file -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:///${activemq.base}/conf/credentials.properties</value>
</property>
</bean>
<amq:broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.base}/data">
<!-- Destination specific policies using destination names or wildcards -->
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry queue=">" memoryLimit="5mb"/>
<policyEntry topic=">" memoryLimit="5mb">
<!-- you can add other policies too such as these
<dispatchPolicy>
<strictOrderDispatchPolicy/>
</dispatchPolicy>
<subscriptionRecoveryPolicy>
<lastImageSubscriptionRecoveryPolicy/>
</subscriptionRecoveryPolicy>
-->
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<!-- Use the following to configure how ActiveMQ is exposed in JMX -->
<managementContext>
<managementContext createConnector="false"/>
</managementContext>
<!-- The store and forward broker networks ActiveMQ will listen to -->
<networkConnectors>
<!-- by default just auto discover the other brokers -->
<networkConnector name="default-nc" uri="multicast://default"/>
<!-- Example of a static configuration:
<networkConnector name="host1 and host2" uri="static://(tcp://host1:61616,tcp://host2:61616)"/>
-->
</networkConnectors>
<persistenceAdapter>
<amqPersistenceAdapter syncOnWrite="false" directory="${activemq.base}/data" maxFileLength="20 mb"/>
</persistenceAdapter>
<!-- Use the following if you wish to configure the journal with JDBC -->
<!--
<persistenceAdapter>
<journaledJDBC dataDirectory="${activemq.base}/data" dataSource="#postgres-ds"/>
</persistenceAdapter>
-->
<!-- Or if you want to use pure JDBC without a journal -->
<!--
<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#postgres-ds"/>
</persistenceAdapter>
-->
<sslContext>
<sslContext keyStore="file:${activemq.base}/conf/broker.ks" keyStorePassword="password" trustStore="file:${activemq.base}/conf/broker.ts" trustStorePassword="password"/>
</sslContext>
<!-- The maximum about of space the broker will use before slowing down producers -->
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="20 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="1 gb" name="foo"/>
</storeUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage>
<!-- The transport connectors ActiveMQ will listen to -->
<transportConnectors>
<!--<transportConnector name="openwire" uri="tcp://localhost:61616" discoveryUri="multicast://default"/>-->
<!--<transportConnector name="default-nc" uri="multicast://default"/>-->
<transportConnector name="openwire" uri="tcp://localhost:61616" />
<transportConnector name="ssl" uri="ssl://localhost:61617"/>
<transportConnector name="stomp" uri="stomp://localhost:61613"/>
<transportConnector name="xmpp" uri="xmpp://localhost:61222"/>
</transportConnectors>
</amq:broker>
<!--
** Lets deploy some Enterprise Integration Patterns inside the ActiveMQ Message Broker
** For more details see
**
** http://activemq.apache.org/enterprise-integration-patterns.html
-->
<cam:camelContext id="camel">
<!-- You can use a <package> element for each root package to search for Java routes -->
<cam:package>org.foo.bar</cam:package>
<!-- You can use Spring XML syntax to define the routes here using the <route> element -->
<cam:route>
<cam:from uri="activemq:example.A"/>
<cam:to uri="activemq:example.B"/>
</cam:route>
</cam:camelContext>
<!--
** Lets configure some Camel endpoints
**
** http://activemq.apache.org/camel/components.html
-->
<!-- configure the camel activemq component to use the current broker -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?create=false&waitForStart=10000" />
<property name="userName" value="${activemq.username}"/>
<property name="password" value="${activemq.password}"/>
</bean>
</property>
</bean>
<!-- Uncomment to create a command agent to respond to message based admin commands on the ActiveMQ.Agent topic -->
<!--
<commandAgent xmlns="http://activemq.apache.org/schema/core" brokerUrl="vm://localhost" username="${activemq.username}" password="${activemq.password}"/>
-->
<!-- An embedded servlet engine for serving up the Admin console -->
<jetty:jetty>
<connectors>
<nioConnector port="8161"/>
</connectors>
<handlers>
<webAppContext contextPath="/admin" resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
<webAppContext contextPath="/demo" resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true"/>
<webAppContext contextPath="/fileserver" resourceBase="${activemq.base}/webapps/fileserver" logUrlOnStart="true"/>
</handlers>
</jetty:jetty>
<!-- This xbean configuration file supports all the standard spring xml configuration options -->
</beans>
The problem I have is using the jetty Namespace.
The schema cannot be found and downloaded: http://jetty.mortbay.org/jetty.xsd
Here a link from Apache ActiveMQ:
http://activemq.apache.org/complex-single-broker-configuration-stomp-only.html
There is not specified any location for this schema.
The ActiveMQ starts without having the schema location but if I use a schema validator like in Eclipse it tells me that I have an error in the file and the schema location cannot be found.
Any idea where I can find the schema for the jetty element ?
I ran into this problem too and I lost a whole hour to find a solution.
Essentially the example in the documentation is outdated.
The dependencies required to enable jetty with activemq-maven-plugin are as follows:
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-xbean</artifactId>
<version>6.1.25</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<version>7.6.7.v20120910</version>
</dependency>
Following is the complete configuration of the activemq-maven-plugin:
<plugin>
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>activemq-maven-plugin</artifactId>
<version>5.8.0</version>
<configuration>
<configUri>${configUri}</configUri>
<fork>false</fork>
<systemProperties>
<property>
<name>javax.net.ssl.keyStorePassword</name>
<value>password</value>
</property>
<property>
<name>org.apache.activemq.default.directory.prefix</name>
<value>./target/</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.8.0</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-xbean</artifactId>
<version>6.1.25</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<version>7.6.7.v20120910</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-leveldb-store</artifactId>
<version>5.8.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>start-activemq</id>
<goals>
<goal>run</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
</executions>
</plugin>
Then to enable jetty is enough to import the jetty configuration file into the activemq the configuration file.
The following snippet is taken from the file ${ACTIVEMQ_HOME}/conf/activemq.xml in the ActiveMQ latest release at the time of this writing (5.8.0):
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<!--
The <broker> element is used to configure the ActiveMQ broker.
-->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
...
</broker>
<!--
Enable web consoles, REST and Ajax APIs and demos
Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
-->
<import resource="jetty.xml"/>
</beans>
Cheers,
Domenico