How beans xml are merged? - java

Suppose I have a project with CDI and beans.xml that have dependency to secondary project that is packaged in some.jar file. In some.jar there is beans.xml too. How they merged after I compile and deploy the main project (in war file)? Can I write only one xml for main project or I must have several separate beans.xml for main and secondary projects?

As described in the documentation each module, jar or war that contains CDI beans in WEB-INF/classes should have beans.xml in order to be processed.
No, you cannot write only one xml for the main project (if by project you mean a war) and by secondary projects you mean jar modules.

Related

Using maven, how to configure a war into a ear file

Im bulding an ear, that has the war of a project inside. It happens that i need a second war place in another directory, to be copied into the same .ear.
Meaning i want my ear, to contain two war files.
One war is the war of the same project where the ear is built, the other war belongs to a different project.
How can i put my pom.xml in the proper way to make this?
thanks
You need to think more Maven-like to solve this problem in Maven. Every project (or module of a multi-module project) creates one artifact (WAR, EAR, JAR, ...). You do not create two artifacts from the same module or project.
If you want to create two WARs and one EAR to bundle them, you need either a multi-module project with three modules or three separate Maven projects.
Two projects/modules create the WARs, and the last one bundles them. The bundling is easy: You just need to reference the WARs as dependencies of the EAR.

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.

Split EJB multiple JARs

Is there a way to separate EJB among multiple JARs?
I want to modularize an EJB application but I want to load classes (session beans and entities from different JARs).
Therefore I have a parent EJB project and child modules.
EJB-PARENT
|____jar module1
|____jar module2
|____jar module 3
I'm using Maven and an EAR to deploy EJBs and its children.
If you tought use multiple ejb jars in war files, then it is OK. Just build the EJBs into ejb jars and put them into the classpath of the WAR project. After that you can refer to the contained EJS-s.
But there is no way a tree like module structure as like in your diagram above.
Well if you used Maven, It will be easy by following
You need to first established
Parent POM by using Maven inside Parent POM project, put all your dependency then create a modules like
parent-project[pom]:
project-name-data.jar
project-name-services.jar
project-name-webservice.war
project-name-ui.war
For Your Session Bean
You can use them in project-name-services.jar
For Your Entities
It can be managed in project-name-data.jar
Actually I solved by using maven shade plugin to generate fat jar

Jar File beans not imported to the Maven project it is used

I created a Maven project which is packages as a Jar file. I used the Jar file to build a UI in another Maven project. But when I create beans of Classes in Jar file I end up getting a null pointer exception for the variables those classes have. But when I wire the bean with the necessary values and beans, I can use the classes present in the Jar file. Is there a way such that I could just create a bean of the class present in the Jar file without wiring the required values and beans?
NOTE: I have wired the required beans and values for the classes in the Jar file in the Jar files Maven project. Shouldn't the UI project be taking values from that wiring made in the Jar file project.

Resources file configurable in multi module maven project

I have one parent project which has WAR and JAR project. Currently the .xml and .properties files are packaged with jar. My requirement is that I want the resources folder of jar project which as .xml and .properties files to be available in WEB-INF folder of the war when the war project is build.
So that I can edit the files when the war is deployed on server.
There are a few ways to share resources across multiple projects or modules:
Cut and paste them.
Use Assembly and Dependency plugins
Use the maven-remote-resources-plugin
the second approach is described here
the third approach is described here

Categories