Jetty Class-loading Issue - spring-boot

I have a Spring Boot Application, which I want to deploy as a war file in jetty 9.0.7.
I am getting spring jar conflict issue,
In jetty start.ini refers to a lib folder with lower version of spring jar for another project,which cant be changed.
But How I can force jetty to ignore those jar & use own WEB-INF/lib jars.
I tried to use in jetty-web.XML but it's not working.
Any other way ?
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/EmiratesIDProxy</Set>
<Set name="parentLoaderPriority">true</Set>
<Call name="prependServerClass">
<Arg>-org.springframework.org.</Arg>
</Call>
</Configure>

Related

Unable to write application logs using externalized Log4j2 XML configuration using Red Hat EAP 7.1.5

I have an application made of Spring Boot WAR packages that need to be migrated to Red Hat EAP 7.1.5.
In my current setup I do the following:
Each WAR has a dedicated log4j2 XML per environment.
This XML file name is defined in the web.xml
The folder containing the log4j2_xxxx.xml is added to the classpath in the JVM startup script.
The WARs are distributed across multiple run-time instances, with a possibility of one run-time hosting more than one WAR.
I would like to replicate the same using EAP. I do see the external log4j2 XML configuration being successfully loaded, however do not see any log statements being written at all.
I am using the following dependencies for packaging log4j2
org.springframework.boot.spring-boot-starter-log4j2 (version 1.5.7)
org.apache.logging.log4j.log4j-web (version 2.10.0)
I have tried the following:
Define a custom module under $JBOSS_HOME/modules/
Add the log4j2 XML in the same folder.
Refer this as global-module in standalone.xml
When I deploy a WAR I can see that the expected log file is created, which means the log4j2 XML configuration is being read successfully. However no logs get written at all in the application log file.
I have tried to get past this by defining a jboss-deployment-structure XML as follows:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.jboss.log4j.logmanager" />
<module name="org.jboss.logging" />
<module name="org.jboss.logging.commons.logging" />
<module name="org.jboss.logging.jul-to-slf4j-stub" />
</exclusions>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
This results in the application logging being removed from the default JBOSS log (server.log) altogether but it does not write the logs to the designated log as well.
I would expect all the logging being done within the application to be written into the file defined by the external log4j2 XML configuration. Any idea what I am missing?

Oracle ORDS directory browsing wouldn't work

I am using Oracle ORDS 3.0.9 and try to enable the directory browsing but keep getting HTTP 403 forbidden error. This is my jetty-http.xml configuration in /standalone/etc folder and I run this command to start 'java -jar ords.war &':
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Call name="setInitParameter">
<Arg>org.eclipse.jetty.servlet.Default.dirAllowed</Arg>
<Arg>true</Arg>
</Call>
</Configure>
The setting is disabled for security. If this is needed, my suggestion would be to deploy ORDS into tomcat where there's much more control over the webserver.

mvn:jetty unable to load WebAppContext

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

AspectJ not seeing META-INF/aop.xml

I am trying to get Load Time Weaving working with my Tomcat 7 webapp, in order to weave a class from an external jar file (located in WEB-INF/lib).
I have done the following:
Started Tomcat with the following parameters: -javaagent:/path/aspectjweaver-1.7.0.jar -classpath /path/aspectjrt-1.7.0.jar:etc
Placed aop.xml into WAR_ROOT/META-INF/, WEB-INF/lib/META_INF, WEB-INF/lib and WEB-INF/
aop.xml:
<aspectj>
<aspects>
<aspect name="ca.gc.agr.agrishare.web.jsf.chartlet.AgriShareGanttRendererAspect"/>
</aspects>
<weaver options="-verbose -debug -XnoInline">
<include within="org.jfree..*"/>
<dump within="org.jfree..*" />
</weaver>
</aspectj>
No matter where I place the file, my target class is not woven, and I keep seeing errors like this:
[WebappClassLoader#495b317b] error can't determine implemented interfaces of missing type javax.validation.ValidatorFactory
when weaving type org.hibernate.cfg.beanvalidation.TypeSafeActivator
when weaving classes
when weaving
[Xlint:cantFindType]
The fact that it is trying to weave a class outside of the package I specified, and considering that server startup time quadrupled, I think that it is trying to weave all classes.
What am I missing?
Figured it out.
WAR_ROOT/META-INF/ is the webapp metadata, looked up by servletContext.getResource("/META-INF/bla").
WAR_ROOT/WEB-INF/classes/META-INF is java classes metadata, looked up by getContextClassLoader().getResource("/META-INF/bla").
I created META-INF/aop.xml in my Config project (which is on the classpath), and everything is working properly now.

jetty load multiple context

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.

Resources