Possibility to access wildfly / app server libraries via jboss-deployment-structure.xml? - jboss

I have a web application running on a wildfly app server (22.X). It contains a war file which has the ability (besides the actual functionality) to query the wildfly itself for its active running sessions via JMX and display that number on an simple html page.
Originally the following dependency was added (via maven) to make this work:
<dependency>
<groupId>org.jboss.remotingjmx</groupId>
<artifactId>remoting-jmx</artifactId>
<version>3.0.4.Final</version>
However this dependency brings lots of other transitive dependencies along like jboss-marshalling, xnio, jboss-threads, wildfly-*, (...) - all packages which does exist within the wildfly app server anyway. So I was wondering whether it is possible to use those app server packages instead of bundling it as part of the war. I tried to add the following to the jboss-deployment-structure.xml to the EAR:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
<deployment>
<dependencies>
<system export="true">
<paths>
<path name="sun/reflect"/>
</paths>
</system>
</dependencies>
</deployment>
<sub-deployment name="service.war">
<dependencies>
<module name="org.jboss.remoting3.remoting-jmx" services="import"/>
</dependencies>
</sub-deployment>
However it didn't work - as soon as the dependencies were removed from the war file it stopped working. My question:
Is it possible to specify/configure the deployment structure file to allow access to the necessary packages from the application server? (I know that this is a wildfly specific solution but this is intended)

It looks like this module has moved to org.jboss.remoting-jmx. The org.jboss.remoting3.remoting-jmx does export the org.jboss.remoting-jmx module in WildFly 22, however the services are not exported which could be the issue.
Either way, it's best to use the org.jboss.remoting-jmx.

Related

I don't want to refer server side jars for my project, My primefaces+spring project has to use the jars that i added to lib folder

I'm working on Primefaces + Spring project.Recently we migrated the project from JSF 1.2 to 2.2 Version.Previously our project was using jsf Implementation and API jars from Project's lib folder but now it's using the jars located in,
**\wildfly-10.0.0.Final\modules\system\layers\base\com\sun\jsf-impl\main**
**\wildfly-10.0.0.Final\modules\system\layers\base\javax\faces\api\main**
and it is throwing Services which failed to start error while deploying on wildfly 10.x,
JBAS014777: Services which failed to start: service jboss.deployment.unit."abc.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."abc.war".POST_MODULE: Failed to process phase POST_MODULE of deployment "abc.war"
How can configure my project to use lib jars.Which will helps in deployment.
Some dependencies are added implicitly by Wildfly 10. You can find a list of them here.
For the web subsystem these are:
javaee.api
com.sun.jsf-impl
org.hibernate.validator
org.jboss.as.web
org.jboss.logging
If you don't want one of them, like in your case com.sun.jsf-impl, you can exclude them using a jboss-deployment-structure.xml file as explained here.
In your case it might look like this:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="com.sun.jsf-impl" />
</exclusions>
</deployment>
</jboss-deployment-structure>
Probably you may need more exclusions, but the principle should be clear.

jboss eap 6.4 oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY

JBoss EAP 6.4 standalone server
Application deployed as a war file throws a runtime exception
java.lang.ClassCastException: oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY
at line
ARRAY a = (ARRAY) cs.getArray(1);
JDBC libary included is ojdbc14.jar (WEB_INF/lib). All libraries are included in the war file and there are no "global" libaries setup on the server. I have verified no other jdbc libraries are included anywhere in the app.
In order to create a JDBC datasource, i created a deployment for ojdbc14.jar. This is the only possible source of conflict i can think of. When i remove the ojdbc14.jar from the war file, i get a ClassNotFound exception in place of the ClassCastException.
Every other part of the app works fine except this line. How do i debug this any further?
I have try something ,but not work:
(1)add a jboss-deployment-structure.xml into web-inf/.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.oracle" slot="main"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
not work and the war dont write the log too.
This error occurs when you have two copies of the class packaged.
Based on your description, one copy is in the deployment for the Oracle driver. The second copy is in the application.
Remove it from application and instead of deploying oracle jar in deployment directory, create module of it.

How to add libraries to Wildfly Application Server using module?

I want to load the Application server Libraries in Java Build Path in Eclipse,
I have 5 applications in Eclipse which shares common libraries,
I can't put all the libraries in each project lib folder,
so i want to add the libraries in Wildfly Application server using modules.
This is my module.xml file add added the lib at WILDFLY_HOME/modules/system/layers/base/com/mysql/main/mysql-connector-java-5.1.23-bin.jar
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.23-bin.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.transaction.api" />
</dependencies>
</module>
After Restarting the server, this module is not loading in Eclipse Build path.
Can any one knows what wrong with this modules ?
In Wildfly I have some predefined modules, those are loading in build path successfully, but user-defined modules are not loading ?
Why ?
Solution found:
Follow below steps :
Go To Eclipse > preferences > Server > Runtime Environments > Default Classpath Entries
Select "Wildfly 8.x Runtime" and add a module
and click on apply, now rebuild your application and check,
the library will be added in buildpath by module name.

How to enable a custom log4j with Jboss AS 7.1

I tried several options. But anything didn't work for me.
Previously I used the same log4j.xml (simple common config) with Tomcat 6,7 and I could able to control the root logging and the application logging with updating the log4j.xml.
When I deploy the same project with JBoss AS 7.1, It only gives me INFO level logging and my log4j.xml doesn't work at all. Sometime this can be fixed by updating some configuration files inside the JBoss server, but I like to know if there a portable way to do it or something similar. If this is bug or something with JBoss AS 7.1 I like to know about a quick fix anyway.
I haven't worked with JBoss before.
Thanks!
I had this problem and solved it by following method:
use your own log4j jar instead of one that provided by jboss. Do it by excluding jboss org.apache.log4j jar module from your application (exclude it in jboss-deployment-structure.xml) and add your own log4j jar file in lib folder of the .ear package.
Now put log4j.xml in the root folder of your module.
By this method you have full control on log4j (like standalone applications).
let me know if you need more help.
Sample jboss-deployment-structure.xml for excluding log4j.jar:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.apache.log4j" slot="main"/>
</exclusions>
</deployment>
<sub-deployment name="MyEjb.jar">
<exclusions>
<module name="org.apache.log4j"/>
</exclusions>
</sub-deployment>

Porting a tomcat web project from eclipse ganymede to intellij 8.1

I have a standard (I think) web project developed with the eclipse IDE. I wish to port it to Intellij idea 8.1 - I think that, among other things, it has better taglib support.
My project structure is as follows:
Project Folder
./src [java source files etc.]
./conf [configuration files - log4j, spring beans...]
./buid [ant files]
./WebContent
./WebContent/images [image files]
./WebContent/META-INF
./WebContent/META-INF/context.xml
./WebContent/pages [.jsp+.html files]
./WebContent/scripts [.js files]
./WebContent/skins [.css files]
./WebContent/WEB-INF
./WebContent/WEB-INF/classes [.class files]
./WebContent/WEB-INF/lib [.jar files]
./WebContent/WEB-INF/tags [.tag files]
./WebContent/WEB-INF/web.xml
I can't seem to get this project configured with my local tomcat server (version: apache-tomcat-6.0.18).
I think that a good answer would be a standard, step by step, cookbook answer as to how to port (and perhaps how to correctly define a tomcat web application within intellij idea).
Thanks all!
I think the first step would be to create a stand-alone build file which will produce a WAR. Do this before attempting to import the project into InteliJ.
I would use Maven. Creating a maven POM file to create a WAR is almost trivial and you can easily override the the default locations for your src, conf, and web content to match you existing src directory. Then test the build by deploying your newly Maven created WAR to Tomcat. I wouldn't think this first task would take more than a half day (at most a full day).
IntelliJ has a built in utility to import Maven projects. Then you should be off and running....
Regardless of the IDE you finally settle on, your project will be much better off in the long run for the Maven migration.
You initial Maven POM file will look something like this...
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany.yourapp</groupId>
<artifactId>yourapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Your project name here</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
*** other dependencies here ***
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>conf</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>WebContent</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
*** This is an example POM only... It's just meant to get you started and may not work "as is".
Start off by creating an empty web application for tomcat, within IntelliJ - and make sure that it deploys correctly
This will produce a directory structure that you should then be able to copy your source files/web assets into.
The thing that you'll probably need to handle differently is the lib files - don't store these directly in the WEB-INF directory, as keeping them in a separate 'library' area, and allowing the IDE to include them in the WAR at build time is generally a better approach, as it promotes re-use across projects.
The key thing to aim for is to not try to set your project up to completely mirror a tomcat application, as the build process will pull together the various parts for you. It all breaks down into 3 sections...
Static assets - images, config files and jsp files (Ok, I know JSP files are kinda dynamic)
Java classes - source code that you write yourself (The IDE will compile these and place them in the appropriate location)
Java Libraries - third party code that you compile against (Again the IDE will place these in the appropriate location)
There are a few bits of configuration, within the project file, that you'll need to tweak to suit your needs, but it's generally straightforward.
By default, log4j will look for it's configuration file (either log4j.xml or log4j.properties) from the classpath of your application. So this means you should place it in WEB-INF\classes, or you can specify a different location with the environment variable log4j.configuration. See the log4j manual.
What IDE you use should have no impact on the structure of your application when it gets deployed to your servlet container. It sounds like maybe you were relying on Eclipse to package the files in a specific way - this is probably a bad practice. Are you using an actual build script?