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
Related
I created 2 spring boot applications.
I used 1 of these jars in the other as a dependency.
Now, both these applications have their own db configurations in their application.properties file respectively.
But when I run the parent project and access classes which use the dependency jar.
The properties defined in the dependency project are not found and the dependency project refers the parent project's (application in which the dependency is used) application.properties file.
How can I make the dependency maven project to use its own application.properties file.
If you are using these dependencies as normal jars, you are probably misunderstanding the way classloaders work.
At any given time you can consider all files provided by the jars on the classpath to be thrown in together in a single large pool (scope/namespace). This mean that if you have TWO "application.properties" files from two different jars, only one of them will be visible.
You need to rethink your deployment scheme so your dependencies does not bring in their own "application.properties" files but they are baked in as part of your deployment packaging.
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
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
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...
I need to use some 3rd party jar in my project. The project is a Spring project and the jar is also using Spring.
Is there a way by which I can include the 3rd party jar in my project? I am finding it difficult to find each and every dependency of the 3rd part jar and inject it.
Shouldn't be a problem. Application contexts can be loaded independent of one another in the same JVM, generally. But if you're loading your bean definitions from a resource file in the classpath (e.g. using ClasspathXmlApplicationContext), make sure the location and name of your file does not conflict with the third-party JAR. For example, if they're both located at "/applicationContext.xml" in different JARs in the classpath, you will have a problem. Make yours unique.
I'm not clear exactly what you mean by "include".
If the 3rd party jar is defined as a dependency in your war project, it will automatically be bundled into the WEB-INF/lib folder of the war when it is packaged by the war plugin. Any class in the jar would then be on the classpath and therefore available to be referenced in your Spring configuration. Do you have a more specific requirement than this?
Also note that if the 3rd-party jar is a properly-defined Maven project, it's dependencies will be defined in its pom. Those transitive dependencies are also bundled into the war (unless you have them defined with a non-default scope in which case they might not be).
Any of the jars you find on the Maven central repository should be defined with all their transitive dependencies. If you're having trouble resolving them, please update your answer so that the relevant Maven credentials can be located.
Update based on your comment. Once the jar is on the war's classpath, you can reference any Spring configuration files it declares by importing them into your war's application context. You just specify the import in the form: "jar:file://jarName!/path/to/config.xml"