Maven multi-project library dependency - java

I have the enterprise project (*.ear), what packaged by maven.
Ear file have include many files:
final.ear
|-lib
|-META-INF
|--web.war
|--bla-bla.jar
|--web-bla.war
Each file (jar, war) packaged by maven.
1) How put all required libraries from all files (war, jar) into final.ear/lib?
2) How group libraries from /lib, for example: lib/axis, lib/logging?

Using the Maven EAR Plugin - Skinny Wars feature has worked well for me for this problem.

1 EJB jar) in the pom.xml of the jar make the dependency "not provided" so Maven knows the dependency is needed on the runtime classpath and thus to be deployed with the application - that will trigger it to add it to the ear/lib.
1 war) Basically what you describe here is that "instead of packaging the dependency with the war, package it in the parent EAR". In Maven terms you then add the dependency to the pom.xml of the ear (so it is on the runtime classpath there), and you mark the dependency as provided in the pom.xml of the war (so it is on the compile time classpath but not on the runtime classpath there). OR use the skinny wars feature as Steve C suggests.
2) The only way I would see this happening is if you micromanage the dependencies in the pom.xml of the ear entirely:
http://maven.apache.org/plugins/maven-ear-plugin/examples/customizing-module-location.html

Related

Wildfly classloading: it's better from modules or from ear dependency?

I've an EAR project that contains a lot of dependencies.
Some dependencies are big jar (more than 4 mb), so i preferred to install them as modules on wildfly and add a module-dependency in jboss-deployment.xml.
For istance we have org.mypackage.MyClass, it's better to load that class from a regular dependency inside the ear/lib dir or from JBOSS_HOME/module ? Are there loss of efficiency?
According to Wilfly Doc:
Class Loading Precedence
A common source of errors in Java applications is including API classes in a deployment that are also provided by the container. This can result in multiple versions of the class being created and the deployment failing to deploy properly. To prevent this in WildFly, module dependencies are added in a specific order that should prevent this situation from occurring.
In order of highest priority to lowest priority
System Dependencies - These are dependencies that are added to the
module automatically by the container, including the Java EE api's.
User Dependencies - These are dependencies that are added through
jboss-deployment-structure.xml or through the Dependencies: manifest
entry.
Local Resource - Class files packaged up inside the deployment
itself, e.g. class files from WEB-INF/classes or WEB-INF/lib of a
war.
Inter deployment dependencies - These are dependencies on other
deployments in an ear deployment. This can include classes in an
ear's lib directory, or classes defined in other ejb jars.
More on: Class Loading in Wildfly

How to remove jar files from war file when deploying a java web application with jboss

I built my netbeans project and it created a .war file including all the .jar libraries. I need to remove my all libraries from .war file. I tried to untick them from library folder but then the project does not deployed. How can I remove my libraries from the .war file and if I remove them where should I put them correctly. In jboss also there is a folder called lib in standalone folder.Should I put them there? If so how to do it. I am not using maven.
If you are using Maven set the dependency scope to the libraries you would like omitted to have scope provided. You can add the dependencies of your WAR to the MANIFEST.MF file or the jboss-deployment-structure.xml file using Maven. If the lirbaries are not JBoss modules by default, eg Orcale JDBC driver, then you will need to create these modules yourself. See the JBoss AS 7 documentation on how to do this.
You can try following approach. I haven't worked on Jboss so don't have detail idea about it.
Deploy each logical library (like "OpenJPA" or "Log4J") as a module, including its api and impl jars and any dependency JARs that aren't already provided by other AS7 modules. If there's already a module add a dependency on it rather than adding a JAR to your module. If several different libraries share some common dependencies, split them out into modules and add them as module dependencies in module.xml.
Use jboss-deployment-structure.xml to have your deployment .war / .ear / whatever declare a dependency on the module if it isn't autodetected and autoloaded.
Courtesy #Craig Ringer.
For complete thread go here

Glassfish deployed project's dependency libraries

I'm new to Java and dependency management.
I have an EJB jar project with a few maven dependencies. When deploying the project to glassfish I get exceptions, that the classes from those dependencies are not found.
So I've added a maven plugin to copy over the dependencies from the local repository to {glassfish_dir}/glassfish/domains/domain1/lib every build.
I'm also using Netbeans.
Is copying over the the dependencies the proper way to go about this? Is there a better way to make dependencies work with glassfish?
The best way is to make the Maven pom.xml that builds the .war declare a dependency on your EJB jar project. That way your EJB jar and any libraries that it has a dependency on, will be included in the .war file that Maven builds.

Add Maven repository to Tomcat's classpath

I'm working with Maven and Tomcat. Some of the web applications I have to deploy use a lot of dependencies that are marked as "provided" in Maven. One example of these dependencies is spring-context.
So, when I package the project, those dependencies are not included in the lib folder of the WAR file.
Because of this, I'm getting
NoClassDefFoundError: org/springframework/context/ApplicationContext
I can't change the scope of the dependencies, and if possible, I don't want to include the dependencies JARs in the WAR file.
How can I add the Maven repository as a classpath to Tomcat, so it can resolve all the "provided" dependencies? Without copying the JARs to Tomcat's lib folder.
I tried the shared.loader property in catalina.properties, but it doesn't work recursively: I have to add each JAR path to the property's value.
A dependency is marked as provided when the app server or container already has it, and you don't have to put it in the war. This is the case i.e. for the servlets jar, but not for the spring-context. I think the better solution would be to mark this dependencies as "compile" instead of "provided".
You have few options here. Like #Andres said, you either add the JARs in the WAR or you add them to the classpath of Tomcat (ie lib folder).
While the concept of having a Maven-aware classloader is interesting, imagine all the possible jar version conflicts that could occur. War A having a provided dependency on Lib v1.0.1 and War B having a provided dependency on Lib v2.1.0, with Tomcat silently resolving these...

Copy dependency to war before packaging

I'm packaging an ear file with maven for an IBM Content Navigator plugin project. This product requires to have an ear, which includes a war, and that war should include the plugin as jar in the root of the war. So not in the WEB-INF/lib. The ear and the war are just empty containers.
So I've created 3 projects, an ear, a web project, and a simple java project. All of these projects have a pom.
How can I create a war which includes the simple java project (jar) in the root of the war? It is not just a dependency as it must not end up in the WEB-INF/lib.
Thanks in advance,
Roeland Bestman
You need to use the maven-dependency-plugin's copy goal and place the jar in a directory under the target directory. Then you'll need to include it from there into your war using the maven-assembly-plugin.

Categories

Resources