My project structure looks like this:
parent POM
|-- app-core
|-- app-model
|-- app-services
`-- app-web
In my pom.xml for app-web:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<webDefaultXml>src/test/resources/webdefault.xml</webDefaultXml>
</configuration>
</plugin>
Hot deployment works properly and have no issues with mvn jetty:run
Question : app-core uses springs how can I configure this JNDI for Jetty maven plugin in this multi-module hierarchy which should be accessible in app-core module
Update :
Have added pom.xml like this
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
<jettyConfig>src/main/resources/jetty.xml</jettyConfig>
</configuration>
</plugin>
And my jetty.xml looks like this :
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="icatDB" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/testDB</Arg>
<Arg>
<New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
<Set name="serverName">localhost</Set>
<Set name="databaseName">test</Set>
<Set name="user">sa</Set>
<Set name="password"></Set>
</New>
</Arg>
</New>
</Configure>
After that when i run mvn jetty:run I get this error
Failure: Object is not of type class org.mortbay.jetty.webapp.WebAppContext
Ok this works for me :
I need to use jettyEnvXml instead of jettyConfig.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
<jettyEnvXml>src/main/resources/jetty.xml</jettyEnvXml>
</configuration>
</plugin>
See this jetty documentation for the configuration of JNDI in Jetty
See this Maven Jetty documentation for the way how to add the configuration files to the build process
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>
I am developing a web application using Spring Boot, and want to generate war instead of jar.
It works fine using the conversion from jar to war described here : http://spring.io/guides/gs/convert-jar-to-war/
But I want to externalize the application.properties from the war, because I want to be able to modify it without opening the war archive.
I already defined the spring-boot-maven plugin.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
com.application.Application
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
I think I need to add Dependency: config to my manifest file.
So, I've done it like that :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>config</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
But when I launch the Application.war on Wildfly 8.4, I've got this
{"JBAS014671: Failed services" => {"jboss.module.service.\"deployment.Application.war\".main" => "org.jboss.msc.service.StartException in service jboss.module.service.\"deployment.screening.war\".main: JBAS018759: Failed to load module: deployment.Application.war:main
Caused by: org.jboss.modules.ModuleNotFoundException: config:main"}}
I would like that my application start with my custom MANIFEST.MF (with Dependency: config) so that I can externalize my application.properties file.
Thank you.
The problem was on the server side !
When you specify a package, you need to add a module.xml file with a Wildfly server.
So in modules/config/main/, I've added my application.properties and a module.xml file that contains :
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="config">
<resources>
<resource-root path="."/>
</resources>
</module>
Thank you for your response #NielsNet.
We have a spring boot app with externalized configuration in a properties file. Executing the jar file like so works:
java -jar -Dspring.config.location="application.properties" app.jar
Executing the jar directly like below works, but without the properties file. Right now, none of these options below take the properties file.
./app.jar
./app.jar -Dspring.config.location="file:./application.properties"
I was hoping we could do something in the pom.xml or in the command that executes to achieve this.
FYI, we have this plugin in the pom.xml to build us the jar file:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<includeSystemScope>true</includeSystemScope>
<!-- This below does not work -->
<!-- <jvmArguments> -->
<!-- -Dspring.config.location=application.properties -->
<!-- </jvmArguments> -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Create file: app.conf (filename is the same as your jar) with content:
JAVA_OPTS="-Dspring.config.location=application.properties"
Similar question was answered here. Documentation for customizing start script can be found here.
In my project I use war overlays. In first base war in src/main/resources I have file my-file.txt. Second war depends on first war.
Second war has a code to lookup for my-file.txt on classpath:
Enumeration<URL> urls = MyListener.class.getClassLoader().getResources("my-file.txt");
while (urls.hasMoreElements()) {
System.out.println("This is my resource:" + urls.nextElement());
}
My output is (mvn jetty:run):
This is my resource:jar:file:/C:/Users/michaldo/.m2/repository/war-plus-war/war1/0.0.1-SNAPSHOT/war1-0.0.1-SNAPSHOT-classes.jar!/my-file.txt
This is my resource:jar:file:/C:/Users/michaldo/workspace-n1/war-plus-war/war2/target/tmp/war1-0_0_1-SNAPSHOT_war1/WEB-INF/lib/war1-0.0.1-SNAPSHOT.jar!/my-file.txt
Can I configure maven jetty plugin and avoid duplication?
My maven-war-plugin configuration (jetty has default configuration):
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archiveClasses>true</archiveClasses>
<attachClasses>true</attachClasses>
<dependentWarExcludes>
WEB-INF/lib/*-*.jar
</dependentWarExcludes>
</configuration>
</plugin>
The problem is that dependentWarExcludes is deprecated (and even not supported in maven-war-plugin 3.0
Maven Jetty plugin works as expected when I move exclusion to overlay config:
<build><plugins><plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<overlay>
<groupId>war-plus-war</groupId>
<artifactId>war1</artifactId>
<excludes><exclude>
WEB-INF/lib/*-*.jar
</exclude></excludes>
</overlay>
</overlays>
</configuration>
</plugin></plugins></build>
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)