jetty load multiple context - maven

We have an maven+springMVC application that uses maven jetty plugin to start the app up when we do development. We use a jetty-env.xml file to set a context and JNDI config. The application will be part of a bigger portal.
We are using maven jetty plugin
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.0.v20101020</version>
with config
<webAppConfig>
<contextPath>/ASX/mainApp</contextPath>
<jettyEnvXml>src/main/resources/jetty-env.xml</jettyEnvXml>
</webAppConfig>
and use jetty-env.xml
<Configure id='jms-webapp-wac' class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/ASX/mainApp</Set>
...
...
</Configure>
Our dir structure is:
MainApp
/forms
page1.html
page2.html
etc...
/WEB-INF
web.xml
PortalApp
/BAL_S
/css
/images
/js
etc...
Now the PortalApp only has static files and is not really a web application i.e. it doesn't have web.xml
The application is dependent on javaScripts from the portal. The location of some of the javaScript are like:
<script src="/BAL_S/js/portal-jquery-lib.js"></script>
<script src="/BAL_S/js/libs/foundation.js"></script>
etc...
As you can see that the location starts with /BAL_S which we are finding tricky to get working as it's like referring to another webapp context. When we start the application with jetty we get javaScript errors because it cannot find /BAL_S
If we deploy our app in tomcat and configure it, as below, the application works fine without any javaScript errors.
<Context path="/" docBase="PortalApp"/>
So the question is how can I do the similar configuration in Jetty so when the application starts up it detects /BAL_S context?
I guess we need to have two contexts in Jetty. How do I configure that?
What is the webConfig for maven jetty plugin to refer to this config?
Hope someone can help. Example would be useful.
Thanks in advance.
GM

OK All I had to do was add to maven jetty plugin configuration, the following:
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<contextPath>/</contextPath>
<resourceBase>src/main/PortalApp/</resourceBase>
</contextHandler>
</contextHandlers>
So this configures context path '/' to 'src/main/PortalApp/' and now we are able to get to /BAL_S in the tag.

Related

JBoss 7 EAP Application Specific Logging with Shared Modules

Maybe I am just completely missing something but I am trying to configure log4j in JBoss 7 EAP with the main goal of isloating application ( WAR ) log messages to unique files.
Our environment has Spring ( 3.X ) configured as a module, and each WAR ( let's call them WAR A and WAR B ) has its own jboss deployment descriptor for Spring as well as a log4j.xml.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="org.springframework.spring" slot="3.2" meta-inf="export" export="true" />
</dependencies>
</deployment>
</jboss-deployment-structure>
log4j.rootLogger = INFO, FILE
log4j.category.org.springframework=DEBUG
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=${jboss.server.log.dir}/webapp_a.log
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=true
log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d %-5p (%-6t) [%X{IP}] [%c] %m%n
Each application creates its own log files, however all the Spring logs are written to the JBoss server.log, and not the application specific log as I would expect. The idea is I would like to see only the spring logs that are relevant to the application in its log file
Am I missing something completely obvious, or really just not understanding how the classloading is working in JBoss 7 where this isn't even possible. Thanks
This is because you have Spring installed as a module. Modules log via the system log context which is configured via the logging subsystem.
Since the org.springframework.spring uses it's own class loader you really wouldn't want the org.springframework.spring module to log with an applications log context. The reason is any static loggers would be configured on whichever application configures the logger first.

RAP application with entrypoint path defined to "/" is not working on Tomcat7

My RAP application has entrypoint defined following
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.rap.ui.entrypoint">
<entrypoint
brandingId="com.ibm.kc.redirect.validator.rap.branding"
class="com.ibm.kc.redirect.validator.rap.app.ApplicationWorkbench"
id="entrypoint"
path="/">
</entrypoint>
</extension>
...
It works fine with IBM WAS Liberty but not on Tomcat7. Tomcat's context root is same as name of war in webapps. So when I access localhost:8080/kc-redirect-tester it should work.I defined entry point to "/" means servlet path after context root is only "/". I see lot of 404 where RWT resources going to localhost:8080/, like they had no idea of tomcat's context root.
In tomcat7, http://127.0.0.1:8080/{appname}/
The appname must be the name of the war (eg. appname.war) and not the value of in your web.xml servlet definition file. then add the context "/", => http://127.0.0.1:8080/{appname}/ (don't forget the last "/")

Spring 3.1 - Servlet 3 code-based configuration using the Jetty Maven Plugin

I try to integrate the new features of spring 3.1 using annotations to specify the configuration information for the web application.
I set up the maven-jetty-plugin version 8.0.4.v20111024 to run my app.
While starting jetty using the mvn jetty:run command, everything seems to be ok and set up correctly.
But when accessing the app through the browser, there is just the output of the default servlet.
It seems to be a simular issue, that tomcat had in previous versions (<=7.0.14)
https://issues.apache.org/bugzilla/show_bug.cgi?id=51278
Currently, I can not use jetty and I had to switch to the tomcat-plugin to deploy my application to tomcat.
Has anyone any suggestions, how to overwrite the jetty default servlet, when no web.xml is available?
You do it by overriding the default jetty config, put this in your plugin:
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<webAppConfig>
<defaultsDescriptor>src/main/resources/webdefault.xml</defaultsDescriptor>
</webAppConfig>
</configuration>
Copy the webdefault file from Jetty, and comment out this part:
<!-- <servlet-mapping> -->
<!-- <servlet-name>default</servlet-name> -->
<!-- <url-pattern>/</url-pattern> -->
<!-- </servlet-mapping> -->

Jetty Maven Plugin is ignoring custom webdefault.xml

I'm trying to get around the common issue of Jetty locking static files on Windows with the technique of setting useFileMappedBuffer to false in webdefault.xml. Unfortunately, every time Jetty is not picking up my customized webdefault.xml.
I'm using Apache Maven 3.0.2. I've tried using the maven-jetty-plugin (v6.1.26) and jetty-maven-plugin (v8.0.0.M2) but with no difference. I've tried running clean and rebuilding as well before running Jetty.
I've verified each time that my webdefault.xml was taken from the same version as the plugin and has the correct settings, namely, only changing this setting from true to false:
...
<init-param>
<param-name>useFileMappedBuffer</param-name>
<param-value>false</param-value>
</init-param>
...
And here's what my pom.xml Jetty plugin section looks like:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>/</contextPath>
<webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
</configuration>
</plugin>
I've also tried altering the path to my file:
<webDefaultXml>${basedir}/src/main/resources/webdefault.xml</webDefaultXml>
Everywhere I've seen this exact solution and it sounds like it is working for others (although I found one instance where someone had my issue). The startup for jetty has this in the output:
> mvn jetty:run
...
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
...
This further makes me think it isn't being applied. All the other paths are correct in the output.
My most direct issue that I'm seeing while Jetty is running is that whenever I edit a static file (JavaScript, CSS, etc.) with IntelliJ IDEA 10, I get this error message:
Cannot save file:
D:\...\... (The requested operation cannot be performed on a file with a user-mapped section open)
After I stop Jetty then it saves just fine. This happens every time.
Any ideas what I could be doing wrong? Thanks in advance.
I found an entirely different doc for the newer Jetty plugin jetty-maven-plugin (v8.0.0.M2) and it looks like the configuration name has changed:
http://wiki.eclipse.org/Jetty/Reference/webdefault.xml#Using_the_Jetty_Maven_Plugin
<project>
...
<plugins>
<plugin>
...
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<webAppConfig>
...
<defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
</webAppConfig>
</configuration>
</plugin>
...
</plugins>
...
</project>
This now seems to work for the newer plugin. I'm still unsure why the v6 plugin does not pick up the customized config.
The only solution I found that worked with maven-jetty-plugin 6.1.24 was this:
http://false.ekta.is/2010/12/jettyrun-maven-plugin-file-locking-on-windows-a-better-way/
The Jetty documentation outlines three ways to do it (as of Jetty 9):
https://www.eclipse.org/jetty/documentation/current/troubleshooting-locked-files-on-windows.html
I successfully used the init-param method in Maven:
<!-- Running an embedded server for testing/development -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.9.v20180320</version>
<configuration>
<webApp>
<_initParams>
<org.eclipse.jetty.servlet.Default.useFileMappedBuffer>false</org.eclipse.jetty.servlet.Default.useFileMappedBuffer>
</_initParams>
</webApp>
</configuration>
</plugin>

Spring deployment-level configuration

When I wrote Java EE apps, I used JBoss Datasources to control which databases the deployment used. E.g. the dev versions would use a throwaway hibernate db, the ref and ops would use stable MySQL deployments. I also used MBeans to configure various other services and rules.
Now that I'm using Spring, I'd like the same functionality - deploy the same code, but with different configuration. Crucially, I'd also like Unit Tests to still run with stub services. My question is this - is there a way, in JBoss, to inject configuration with files which live outside of the WAR/EAR, and also include these files in test resources.
It is possible to add objects into the JNDI context by placing a file named xxx-service.xml into jboss's deploy directory. The app could then lookup the values via JNDI. In the example below the string "development" is added at java:/modes/deployment. To use JNDI in your unit tests use the org.springframework.mock.jndi package.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd">
<server>
<mbean code="org.jboss.naming.JNDIBindingServiceMgr"
name="c3po.naming:service=jndi-bindings">
<attribute name="BindingsConfig" serialDataType="jbxb">
<jndi:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd"
>
<jndi:binding name="java:/modes/deployment">
<jndi:value type="java.lang.String">development</jndi:value>
</jndi:binding>
<jndi:binding name="java:/sites/abc">
<jndi:value type="java.lang.String">dev.site.example.com</jndi:value>
</jndi:binding>
<!-- Examples:
<jndi:binding name="urls/jboss-home">
<jndi:value type="java.net.URL">http://www.jboss.org</jndi:value>
</jndi:binding>
<jndi:binding name="hosts/localhost">
<jndi:value editor="org.jboss.util.propertyeditor.InetAddressEditor">
127.0.0.1
</jndi:value>
</jndi:binding>
<jndi:binding name="maps/testProps">
<java:properties xmlns:java="urn:jboss:java-properties"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
<java:property>
<java:key>key1</java:key>
<java:value>value1</java:value>
</java:property>
<java:property>
<java:key>key2</java:key>
<java:value>value2</java:value>
</java:property>
</java:properties>
</jndi:binding>
-->
</jndi:bindings>
</attribute>
<depends>jboss:service=Naming</depends>
</mbean>
</server>

Resources