Deployed Web application getting nosuchmethod error for javax.json.JsonValue.asJsonArray - Jboss eap 7.0 linux server - jboss-eap-7

I have a web application deployed to jboss eap 7.0 on linux.
Within my java code I am using javax.json.JsonValue.asJsonArray method.
When I run locally on tomcat all runs fine.
Once I deploy to Jboss I get a nosuchmethod error on asJsonArray method. within my WEB-INF\lib folder I have the necessary json jar with that method javax.json-1.1.4.jar. I have discovered that under modules within Jboss it has its own version of javax.json \jboss-eap-7.0\modules\system\layers\base\org\glassfish\javax\json\main\javax.json-1.0.3.redhat-1.jar.
It is my speculation that when I run my application it is first looking at jar within the Jboss modules directory rather than the jar within the WEB-INF\lib folder in the war file. How do I direct the application to reference the jar within the WEB-INF\lib and not the jar withing the jboss modules?

You can exclude the JBoss provided dependency using jboss-deployment-structure.xml file which you need to place under the WEB-INF directory of your war. You have to specify the exclusion dependencies something like below.
`<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="$LIBRARY_OR_MODULE_YOU_WANT_TO_EXCLUDE"/>
</exclusions>
</deployment>
</jboss-deployment-structure>`
e.g. <module name="javax.json.api"/>

Related

How to run spring batch application without spring boot maven plugin

Is it possible to run a spring batch application without spring boot maven plugin?
I need to run the application on another server and transferring a big jar (with spring dependencies) is time consuming. For this reason I want to compile and create a jar without spring dependencies included inside the jar and run it from command line.
If you want to create a simple JAR without spring boot dependencies, remove spring-boot-plugin from build.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
Above snippet should not be present in your pom.xml.
With this, fat/uber jar won't be created.
To run built jar:
java -cp MyJar.jar:lib/* com.somepackage.subpackage.Main
Where your libraries are contained in lib directory relative to current directory and MyJar.jar is the name of the jar built with maven.

Websphere Liberty Profile: [WARNING ] SRVE0190E: File not found in library that is contained in the EAR file

Currently I have a problem during migrating a Java Enterprise project form old WAS-8 to Liberty Profile 17. In my case the environment cannto find a bunch of css/js files in the richfaces jar. Loading a page in the browser, WLP17 writes warnings like this into the logfile:
[WARNING ] SRVE0190E: File not found: /org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.5.17.Final/PackedCompressed/org.richfaces/jquery.js
I build the project using maven and I defined the richfaces dependency in the parent pom like this:
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces</artifactId>
<version>4.5.17.Final</version>
</dependency>
Then, I have several EJB and WAR projects that are packed together into an EAR file. The WAR projects using richfaces contain a richfaces dependency with scope provided:
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces</artifactId>
<scope>provided</scope>
</dependency>
Finally, the EAR pom has the dependency on richfaces to ensure that the library is included in the EAR file. For any reason the liberty is not able to find resources located in the richfaces jar.
I inspected the created EAR file, it contains the richfaces libraries. Then, I inspected the richfaces libraries, the also contain the files that are not found.
Is there any more configuration I have to do?
Jar libraries which are expected to serve static files from META-INF/resources/ should be bundled in the web application WAR. Section 4.6 from the Servlet 3.0 spec is relevant:
The getResource and getResourceAsStream methods take a String with a
leading “/” as an argument that gives the path of the resource
relative to the root of the context or relative to the
META-INF/resources directory of a JAR file inside the web
application’s WEB-INF/lib directory...
#wtlucy's comment did solve my problem. Thank you.
I have put the richfaces libraries into the WAR files that need these libraries.

How is a war file created for spring boot with maven?

I'm trying to follow the guide for converting a spring project to a war.
http://spring.io/guides/gs/convert-jar-to-war/
It starts out using maven and gradle and then right after the jar portion it completely forgets about maven and only has gradle updates.
There are two main changes that you need to make in the pom. The first is to change the project's packaging type to war:
<groupId>org.springframework</groupId>
<artifactId>gs-convert-jar-to-war</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>
The second is to add a dependency on spring-boot-starter-tomcat and mark it as provided:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
mvn package will now produce a war file that can be run using java -jar or deployed to a separate servlet container.
There is an official guide at spring:
http://spring.io/guides/gs/convert-jar-to-war-maven/
Pay attention to "Initialize the servlet" section.
It explains an important point of adding a class that substitutes web.xml. Without it (or without proper web.xml) you will get a war file but when deployed nothing will be accessible in browser as nothing will be registered as your request dispatcher.
Also note that it is best to run this example on Tomcat 8 as it supports latest servlet specs. I have spent number of hours trying to figure out why it does not work on my Tomcat 7.

Jboss EAP 6.1 spring modules class loading not working

I have a spring integration project deployed in jboss as a WAR file.
The project uses maven and structured to support any type of archival War or Jar.
However, the dependencies of the project (all spring jars and custom jars) should be externalized
The reason would be that, later there would be 100s of Spring Integration flows would be deployed and if we have the jars in WEB-INF/libs the size of WAR grows to ~ 50MB. As we have abstracted much of our functionality in a seperate jar (would be added as dependency to my spring integration project), Externalization will result in reducing the WAR file to ~ 5 KB.
I do not have a web.xml and use the WebInitializer for loading the context (Which is part of my common functionality and added as dependency)
Below is what I have tried with JBOSS.
Created a module com.xxx.yyy and added all my spring/third party and custom jars as resources.
Added the dependency to manifest file. (This did not work)
Added the jboss-deployment-structure.xml to my war WEB-INF (did not work)
If I give the wrong module name its throws errors as module
not found.
The war gets deployed, but not initialized. If I have the dependencies in my WEB-INF/lib, everything works as expected.
Below is the jboss deployment structure xml that I used.
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<dependencies>
<module name="com.xxx.yyy" services="import" >
<imports>
<include path="META-INF**"/>
<include path="org**"/>
</imports>
</module>
</dependencies>
</deployment>
</jboss-deployment-structure>
Here is the expectation,
Externalize the Jar dependencies.
Import the dependencies to my war(manifest or jboss-deployment-structure.xml)
Should be used Spring Service should be initialize.
The deployed war should be working as it does if the libraries are
in WEB-INF
Please help...
With JBOSS EAP 6, Its not possible to deploy the war without a web.xml, But such is possible only with tomcat or by using spring boot.
Also, to address this problem, we had to create a dummy web.xml and use jboss modules to load dependencies.

how to deploy wab files in glassfish

What is the correct process of deploying a WAR OSGI file (WAB) to glassfish 3.1 server?
I am copying the war file to "glassfish3\glassfish\domains\domain1\autodeploy\bundles\" -> OSGI recognizes the file as bundle and add it to its container.
However, it doesn't deploy the war as web application (I cannot access its JSPs).
To make it a web application, I deploy the war from glassfish admin console.
Is it correct to deploy the same war twice? Shouldn't OSGI deploy it as WEB and OSGI?
To make OSGI discover the wab, I needed to add the following attributes to "maven-bundle-plugin" when creating the WAB:
<configuration>
<instructions>
<Web-ContextPath>/blabla</Web-ContextPath>
<Webapp-Context>/blabla</Webapp-Context>
</instructions>
</configuration>
With this configuration, war should be copied to autodeploy/bundles only.
More details (and other attributes) can be found here: http://leshazlewood.com/2010/09/08/osgi-maven-pax-and-web-applications/
You only Web-ContextPath as per the final OSGi EE spec. Webapp-Context was an intermediate name. No need to deploy the WAB again as a WAR as already answered in this thread.

Resources