jar as jboss module: dependencies - java

I have a question about JBoss modules dependencies vs war dependencies.
I have an app.war; its webinf/lib directory contains a myLib.jar only. In this configuration everything works fine.
Now I have to move mylib.jar outside the war, so I put it into a JBoss module and added it to module.xml; I also added it to the deployment-structure.xml file in the war.
In this new configuration my app.war finds succesfully the external myLib.jar but now myLib.jar cannot find its dependencies anymore.
Specifically it doesn't find rowset.jar as I get this exception:
java.lang.NoClassDefFoundError: com/sun/rowset/CachedRowSetImpl
Why can’t myLib.jar see all the libs it used to see when it was deployed inside the war? Do I have to create a JBoss module with myLib dependencies?
Thanks

modules must have their own dependencies explicitly declared in the modules.xml. A Module cannot access jars that are part of a deployment.

Related

How to include only specific jar from libs into gradle build?

I'm using gradle V4.10.2 and eclipse for building WAR files. I have some common JAR files for all the wars. I need them to use only during compile time and need to exclude them while building into WAR file. Also I don't want to exclude all the JARs file.
I've put all the JARs in libs folder. In build.gradle, I have specified only the JARs to be included. Since the exclude list is bigger then include list of JARs I'm not using exclude
war {
rootSpec.include("**/test.jar")
}
The above results the WAR file without META-INF folder. Hence, webapp is not started. I have tried adding the libs as reference lib in eclipse but that results in compilation error.
Execution failed for task ':compileJava'.
Compilation failed; see the compiler error output for details
So I have to include all the JARs in libs folder and then need to use only required JARs in the WAR built. How to include only specific JARs into build?
I strongly recommend reading about building Java projects with Gradle and in particular the part about web applications
In short you should add the JARs needed for compilation only to the compileOnly configuration and the JARs needed for compilation and at runtime in the implementation configuration.
Gradle will then use all of them for compilation and only include the ones in implementation when packaging the WAR.
While you can do that by selecting them from your libs folder, I strongly recommend moving to libraries and its metadata sourced from a repository, private or public, so that the dependency management is done for you.

Setting up EJB build classpath in Eclipse

I have installed Eclipse, WildFly and Jboss Tools. I created an EAR/Maven project and an EJB/Maven project.
I added all the dependencies to the EAR pom.xml. Jboss Tools deploys the WildFly EAR lib with no issues and the application runs fine.
The problem is the build classpath in the EJB project in Eclipse. As all the dependencies are configured in the EAR pom.xml and not in the EJB pom.xml, I cannot figure out how to tell the EJB project in Eclipse to take from the EAR project the jars that were defined as dependencies.
How to set this up?
Add the dependencies in EJB pom.xml and not in EAR pom.xml.
You want to "take from the EAR project the jars that were defined as dependencies", but this is not how Maven works.
Jars are drawn from a Maven repository (like MavenCentral or your local repository), according to the dependencies that are defined in the pom. As #N.Shrivastava already said, you define the dependencies in the pom of the project that actually uses the dependencies. So when you have an ear that includes an ejb jar that has some dependencies, put the dependencies into the pom of the ejb jar and delete them from the pom of the ear. They will be transitively drawn into the ear as well.
If you need the same set of dependencies in different ejb jars, this can be realised by creating a separate project of packaging pom. Then the different ejb jars can depend on that pom project, and draw transitively all the dependencies from the pom project.

EJB Timer (#Schedule) not recognized by WildFly when inside a JAR which is also inside an EAR

I have an EAR file with 3 WARs and some common dependencies within lib/ folder. One of those dependencies has an EJB with a scheduled method, but it seems that the server is not recognizing it. No evidence in log, no code executed.
But when I deploy a simple war with the same jar within WEB-INF/lib, it works. I've already tried to package the jar as an ejb-jar with the maven plugin, but no success at all.
Any ideas on what must be going on?
Jars in the lib directory of an EAR are not considered to be EJB jars and their content is not considered at deployment time in that respect. The lib directory only exists to make it easier to provide library jars whose classes are automatically made visible to all the modules in an EAR file.
Your EAR file contains a META-INF/application.xml file that lists out the various modules that it contains. Prior to Java EE 6, only ejb-modules were considered for potential EJBs. Java EE 6 and newer added web-modules to that list. All jars within a web-module's WEB-INF/lib directory are considered to be part of the web-module, even if they contain ejb-jars. Any ejb-jar.xml files found within a web-module are merged together. This applies even if the web-module is deployed as a standalone WAR file.

Create a WAR from the java files using Gradle script

My directory sturcture is,
C:\Grapher\src\ *.java
C:\Grapher\lib\ *.jar
There are many java files and many jar dependencies. I want to create a tomcat deployable WAR.
Can any one suggest me how to create a WAR using a gradle script? What are the dependencies to be included in Gradle to create a WAR.
Have you read and understood https://docs.gradle.org/current/userguide/war_plugin.html?
The War plugin adds two dependency configurations named providedCompile and providedRuntime. Those two configurations have the same scope as the respective compile and runtime configurations, except that they are not added to the WAR archive. It is important to note that those provided configurations work transitively. Let's say you add commons-httpclient:commons-httpclient:3.0 to any of the provided configurations. This dependency has a dependency on commons-codec. Because this is a “provided” configuration, this means that neither of these dependencies will be added to your WAR, even if the commons-codec library is an explicit dependency of your compile configuration. If you don't want this transitive behavior, simply declare your provided dependencies like commons-httpclient:commons-httpclient:3.0#jar.
If you use providedCompile or providedRuntime, those dependencies will not be added to your war archive.
The folder structure you need to have in your project is:
app
|-src
|-main
|-java
|-webapp
In the java folder you add your own packages and classes. In the webapp folder you add web content if your application makes use of such items.

Reference library not deployed as a module

How do I reference a library deployment that is not in the modules folder from an ear deployment in jboss 7? I have a common library (jar) deployed ok, and an ear deployment fails because it can't not locate the classes deployed in the common jar from earlier
It should go into the lib/ folder in the EAR and <library-directory/> needs to be set in META-INF/applicaiton.xml.
If you deployed the common JAR you need to add a dependency in the MANIFEST.MF of your EAR or create a jboss-deployment-structure.xml. The class loading documentation has more details.
The module name of the deployment should be something like deployment.name_of_deployment.jar.

Categories