How can I serve static content with maven jetty plugin (7.x)
Thanks
put your static contents under any folder below /yourStaticApp/src/main/webapp -- say under /yourStaticApp/src/main/webapp/static. When you will run Jetty these will be available as http://host:port/contextRoot/static/fileName.ext
Hmmm, unsure, if that's possible. Eclipse Jetty Maven plugin documents a way to configure static source location, which boils down to the alternate location of webapps mentioned above.
...
<plugin>
...
<configuration>
<webAppSourceDirectory>${basedir}/src/staticfiles</webAppSourceDirectory>
...
</configuration>
...
</plugin>
...
As the doc points out:
<webAppSourceDirectory>–By default, this is set to ${basedir}/src/main/webapp. If your static sources are in a different location, set this parameter accordingly.
refer: http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
Update: On some more reseach I found out that you can actually point the location of webdefault.xml from in Jetty-maven plugin; and in webdefault.xml you can configure the static content location.
In your Jetty Maven configuration, point the location of wendefault.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
...
<defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
...
</configuration>
</plugin>
Now, with webdefault.xml in your hand you can put the configuration mentioned here: http://docs.codehaus.org/display/JETTY/Static+Content -- except the package Names has been changed from org.mortbay.jetty... to org.eclipse.jetty... see below:
<Configure class="org.eclipse.jetty.servlet.Context">
<Set name="contextPath">/javadoc</Set>
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set>
<Call name="addServlet">
<Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
<Arg>/</Arg>
</Call>
</Configure>
refer: http://wiki.eclipse.org/Jetty/Reference/webdefault.xml
I haven't tested/used the above. But let me know, if you get this working. Or if anything else needed to get this done.
I have such a configuration at my jetty.xml. I have just wanted to updated my question.
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.HandlerList">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New class="org.eclipse.jetty.servlet.ServletContextHandler">
<Set name="contextPath">/static</Set>
<Set name="resourceBase">${static-resources-path}</Set>
<Call name="addServlet">
<Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
<Arg>/</Arg>
</Call>
</New>
</Item>
</Array>
</Set>
</New>
</Set>
This is a config which works for me, using the resourceBase and contextPath values on the JettyWebAppContext
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.7.v20170914</version>
<configuration>
<scanIntervalSeconds>60</scanIntervalSeconds>
<webApp>
<contextPath>/app</contextPath>
</webApp>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<contextPath>/images</contextPath>
<resourceBase>./../../env/localhost/config/images</resourceBase>
</contextHandler>
</contextHandlers>
Related
I have a weird situation, when trying to run jetty from eclipse. I updated my old project from jetty 7 to jetty 9.3.7.v20160115. But, now when starting the jetty:run with m2eclipse I got the following exception:
java.lang.IllegalArgumentException: Object of class 'org.eclipse.jetty.maven.plugin.JettyWebAppContext' is not of type 'org.eclipse.jetty.webapp.WebAppContext'. Object Class and type Class are from different loaders. in file:/xx/WebApp/src/main/webapp/WEB-INF/jetty-env.xml
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:295)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:245)
at org.eclipse.jetty.plus.webapp.EnvConfiguration.configure(EnvConfiguration.java:116)
From the message I can see that the two classes are not the same. But from the documentation I need to use the class org.eclipse.jetty.webapp.WebAppContext and org.eclipse.jetty.maven.plugin.JettyWebAppContext is a subclass of WebAppContext. So it is not clear for me if the condition in line 292
oClass.isInstance(obj)
is correctly used there.
I have defined in jetty-env.xml file the following entries:
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="resInspector" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref refid="wac"/></Arg>
<Arg>jdbc/xxx</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">org.postgresql.Driver</Set>
<Set name="url">jdbc:postgresql://xx:5432/xx</Set>
<Set name="username">xx</Set>
<Set name="password">xx</Set>
<Set name="maxActive">100</Set>
<Set name="maxIdle">30</Set>
<Set name="maxWait">-1</Set>
<Set name="defaultAutoCommit">false</Set>
</New>
</Arg>
</New>
</Configure>
Next I added in web.xml those entries
<resource-ref>
<description> JNDI resource</description>
<res-ref-name>jdbc/xxx</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
thanks for any help.
Markus
The error message says :
Object Class and type Class are from different loaders
So the object class obj.getClass() and the type Class oClass may be equal or the same, but loaded from different classloaders.
Possible reason could be that you have this class twice in your classpath. Once through dependencies of the jetty plugin and once in your pom.
Use mvn dependecy:tree to check that and exclude the dependency of your pom.
You also may try to change the class in
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
to
<Configure id='wac' class="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
indeed it was related to some duplicated jar files. In my maven pom file I had unnecessary files (jetty-plus,jetty-annotations,jetty-jndi,jetty-xml).
Removing those jar file from my maven file solved the problem.
thanks for your suggestion
In my ServletFilter, I want to use specific jetty API exposed in the HttpServletRequest implementation.
I launched it like that:
final Request jettyRequest = Request.getBaseRequest(request)
If I want to avoid ClassNotFoundException, I must add the jetty-server artifact to my maven dependencies. But if I do that, getBaseRequest returns null because 'request instanceof Request' returns false instead of true.
This is certainly due to conflict between jetty and application classloaders because both of them have loaded 'org.eclipse.jetty.server.Request' class. I tried several configurations, but I was not able to make the Request class exposed to my webapp without adding the dependency in WEB-INF/lib, which causes the classpath issue.
My application is launched with "mvn jetty:run-forked" and configured like this:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-version}</version>
<configuration>
<webAppSourceDirectory>${project.build.directory}/${project.name}</webAppSourceDirectory>
<systemProperties>
<force>true</force>
</systemProperties>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
<jettyXml>../jetty.xml,../jetty-ssl.xml,../jetty-https.xml</jettyXml>
<jvmArgs>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/alpn/alpn-boot/${alpn-version}/alpn-boot-${alpn-version}.jar</jvmArgs>
</configuration>
</plugin>
Any help will be appreciated!
I fixed the issue by adding a WebAppContext configuration file that contains:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="parentLoaderPriority">true</Set>
</Configure>
The file must be referenced in jetty-maven-plugin like that:
<contextXml>../jetty-context.xml</contextXml>
Suppose I have a Web.config like such:
<configuration>
<elmah>
...
</elmah>
</configuration>
Is it possible to remove the <elmah> node with config transforms? So far I've tried something like:
<configuration>
<elmah xdt:Transfrom="RemoveAll"/>
</configuration>
Which doesn't work (according to Preview Transform). Althought this type of thing does seem to work on other nodes. Does anyone know how this can be removed?
Thanks
You need to have a xdt:Locator to get the match.
Try using the following:
Debug:
<configuration>
<elmah name="debug" />
</configuration>
Release:
<configuration>
<elmah name="debug" xdt:Locator="Match(name)" xdt:Transform="RemoveAll" />
</configuration>
Or without the need for name matching:
<configuration>
<elmah name="debug" xdt:Locator="XPath(//elmah)" xdt:Transform="RemoveAll" />
</configuration>
or
<configuration>
<elmah name="debug" xdt:Locator="XPath(configuration/elmah)" xdt:Transform="RemoveAll" />
</configuration>
As a note:
Currently the Web.config transforms are only applied during the Web Publish Pipleline (WPP) that is on Publish, not during debug, to enable them during debug check the following link: http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx .
Hope it helps.
You have a typo in your xdt syntax – it should be xdt:Transform, not xdt:Transfrom.
I have a situation where we wrap a jar with JSmooth to get an suitable exe file.
This has traditionally been built by ant, and as part of our general mavenification the current, short-term solution has been to use maven-antrun-plugin to set a property and invoke ant.
Unfortunately this approach fails when building on Unix (as there is no X11 display available) and the solution is to invoke the JVM with -Djava.awt.headless=true. I would like to do this in my pom.xml but cannot identify where to do this.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<!-- create one-jar and exefy it -->
<property name="maven.project.build.finalName" value="${project.build.finalName}" />
<!-- note: fails on headless Linux for now -->
<ant />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
It is ok to fork a new JVM directly but not to rely on platform specifics.
How can I do this correctly?
As far as I know, the solution without forking JVM is to use MAVEN_OPT
export MAVEN_OPTS="-Djava.awt.headless=true"
Since -D is JVM option, you had to specify it to maven directly. You cannot (once again, from what I know) pass it as internal argument (and there isn't any configuration option that allow it)
So, using MAVEN_OPT parameter become the right way to do it.
EDIT 1:
You can have a glance here using better-maven2-antrun-plugin
http://code.google.com/p/better-maven2-antrun-plugin/wiki/Usage
EDIT 2:
Can can maybe help maven-antrun developpement providing them a way to specify those parameters, like maven-compiler-plugin. This would be the best way if you really want to use pom informations.
The ant manual has a section titled "Running Ant via Java" that shows how to do just what you want. A slightly tweaked version of their example is reproduced below:
<java
classname="org.apache.tools.ant.launch.Launcher"
fork="true"
failonerror="true"
dir="${basedir}"
taskname="headless-ant"
>
<classpath>
<pathelement location="${ant.home}/lib/ant-launcher.jar"/>
</classpath>
<arg value="-buildfile"/>
<arg file="${ant.file}"/>
<arg value="-Dbasedir=${basedir}"/>
<jvmarg value="-Djava.awt.headless=true"/>
</java>
If you put that snippet in place of the <ant> element in your snippet, it should do the trick.
My goal is simple. Configure the maven-jetty-plugin with a JNDI for javamail.
But after hours of googling and reading i cannot figure out exactly what to do....
Can someone please help me with a simple step-by-step instruction.
I just read the documentation at http://docs.codehaus.org/display/JETTY/JNDI, but there is absolutly no information about what file i should be editing...
For example. Where am i supposed to put this???
<Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext">
...
<New id="mail" class="org.mortbay.jetty.plus.naming.Resource">
<Arg><Ref id="wac"/></Arg>
<Arg>mail/Session</Arg>
<Arg>
<New class="org.mortbay.naming.factories.MailSessionReference">
<Set name="user">fred</Set>
<Set name="password">OBF:1xmk1w261z0f1w1c1xmq</Set>
<Set name="properties">
<New class="java.util.Properties">
<Put name="mail.smtp.host">XXX</Put>
<Put name="mail.from">me#me</Put>
<Put name="mail.debug">true</Put>
</New>
</Set>
</New>
</Arg>
And lastly. Since this is the maven-jetty-plugin, i do not have access to modify any core files, so should there be some kind of xml file i should create and set up to override jetty original configuration?
Add the following configuration to the maven-jetty-plugin:
<jettyEnvXml>src/jetty-env.xml</jettyEnvXml>
Then, you can place that file in that location.
Here are concrete examples:
pom.xml (line 536)
jetty-env.xml