During my migration from weblogic to wildfly 16, I need to implement the concept of a shared library but all I am is getting class loading issues. I am new to the concept of modules.
I created a folder for the library with jars in modules and created a module.xml. I used jboss-deployment-structure.xml to map the dependency to the shared library. The EAR gets the external jar but I am getting a class not found for the jar inside the EAR. It seems the jar inside the EAR is being excluded when I add the jboss-deployment-structure.xml to the EAR. Without the
jboss-deployment-structure.xml I am able to deploy and login to my application but cant implement the functionalities of the shared jar.
The above image is the jboss-deployment-structure.xml I used.
The above image is the module.xml I used.
This is the server log I got on deployment with reference to the module created, It shows that the file "FileItem" is not found in the location I created but the jar with that class is already present in the EAR. Why is it not being read ?
According to the error in the screenshot, JBoss is not able to resolve your dependency com.lib. The module you created i.e. com.lib should be present in one of the following locations :
$JBOSS_HOME/modules/
$JBOSS_HOME/modules/system/layers/base
e.g. For location according to 1, The directory structure will be like :
$JBOSS_HOME/modules/com/lib/main
You will have following files at this location
module.xml
ebsUtility.jar
SessionHandler.jar
Related
We are using Websphere 9 application server. We want some of the configuration files such as xml and properties files in a separate directory of Websphere server and want them too see accessible by ear/war file during the run time. I heard about shared libraries approach, but it apppears that only class and jar files can be used as shared libraries, but not xml and other files. Can anyone tell me an alternative solution where the external xml configuration files be made available for war/ear file during run time or in class path?
If you add a directory as a shared library path, the directory itself will be added as a class path entry to any class loader referencing the shared library (along with any jar/zip files within it), so you'll have access to loose files such as XML files through the getResource() API.
Note that the argument to getResource() needs to be relative to the location within the directory. For example, if you have the file test.xml, you could add it to the directory /sharedlib, created a shared library named "library1", and associate it with your EAR or WAR, and then your application could use use this to get at the file:
this.class.getResource("test.xml");
That would return you a URL pointing at /sharedlib/test.xml.
I deployed an EJB application (provided as a .war file) to TomEE Plus 7.1.0.
It runs alright, but it was noticed that emails were not being sent.
I investigated the log file at logs/tomee-stderr.[date].log and found this:
java.lang.LinkageError: loader constraint violation: loader (instance
of java/net/URLClassLoader) previously initiated loading for a
different type with name "javax/mail/Session"
followed by a very, very long (>500k lines) stack trace.
I found a related question (java.lang.LinkageError: loader constraint violation:previously initiated loading for a different type with name "javax/mail/Session") and it is said the solution consists in marking the dependency to javamail as a "provided" dependency, but my understanding is that this is supposed to be done in the Maven project file, to which I don't have access.
I can edit the contents of the ROOT directory at will (and I tried deleting two files, namely, mail.jar and mail-1.4.4.jar, from the WEB-INF/lib directory, but to no avail); I believe I can also edit the .war file with 7-zip; and finally I can modify any configuration in the server. But I cannot edit the application's source code and/or recompile it.
(As potentially relevant information, I do have read access to the source code, and it does not appear to use Maven - the existence of a .project file suggests it is an Eclipse project.)
A file named geronimo-javamail_1.4_mail-1.9.0-alpha-2.jar is part of TomEE and is located in the lib folder.
Given my constraints (no maven, no compilation - existing WAR file must work), how can this error be solved?
[Edit 1]
I removed both mail.jar and mail-1.4.4.jar from the WAR file (with 7-zip) and re-deployed, resetted the log file but the error remains the same.
I tried deleting geronimo-javamail_1.4_mail-1.9.0-alpha-2.jar from TomEE's lib folder, but TomEE fails to start.
It seems that there is still a jar file that contains the javax.mail.Session class? Please extract all the WEB-INF/lib to an folder and search for the content of all the jar files if it contains the string "javax/mail/Session"
I found several similar topics, like reading from inner structure etc, however it still does not solve my problem.
Project structure:
whole project -> war, which has:
several jar's connected as dependency
in pom.xml;
context.xml in META-INF folder, which I need to read from one of jars.
part of it -> jar, which is dependency in war's pom.xml
I've tried a few solutions like:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream("META-INF/context.xml");
However I did not expect that to work as I think my jar searches for this resource in its structure, not in war.
I need jar project to read context.xml from war project. So, jar is like inner structure and war is outer. Is that possible to do?
With getResourceAsStream() you have access to all resources in the classpath.
The classpath of a webapplication consists of every jar under WEB-INF/lib and every file under WEB-INF/classes
META-INF is not in the classpath.
Please read the question: How to get resource from the context.xml file in tomcat webapp?
I need to read a properties file located inside an ear. In jboss 5.1 I put the file in the root of the ear and it works, but in wildfly it doesn´t.
In wildfly, I managed to read the property file outside the ear according to this
http://blog.jyore.com/?p=58
But I haven´t found the way to do the same but with the file inside the ear. I´ve tried without success putting the file in the METAINF folder, also tried with the "Class-Path: ." in the manifest...
Please any ideas?? Do I have to put the file in any specific location??
I found the solution:
In WildFly 8, to get those properties available in the classpath, package them within your application. For example, if you are deploying a .war then package those properties in WAR WEB-INF/classes/ folder. If you want those properties accessible to all components in a .ear, then package them at the root of some .jar and place that jar in EAR lib/ folder.
https://docs.jboss.org/author/display/WFLY8/How+do+I+migrate+my+application+from+AS5+or+AS6+to+WildFly
Thanks for your help
My requirement is I have to refer the jars present in other war file in my web application.
I am thinking to edit the manifest file of my web application to add the jars of other war file, but I do not know exactly what to add in the manifest file.
Could any one please help me on this.
You web application should be running inside at least a Servlet Container, right?
So you have to move your second webapp jars inside the library directory of your Application Server (e.g. lib for Tomcat AS) and that way the classes under those jars will be available for both web application (even all web application running in you AS).
Note: It is already a bad practice to package a common dependencies under a war archive as those should be shared among multiple contexts, so you should review you packaging strategy.
Edit: How to declare a Shared classpath in Tomcat
To define a shared classpath in Tomcat AS so that all your contexts have access to:
Navigate to your server home ($CATALINA_HOME) and open the catalina.properties file under the conf/ directory.
Look for the shared class loader section and add / modify shared loader to look as follows:
shared.loader="/path-to-shared-classes"
You need to look for the classpath form rules, yours may be "$CATALINA_HOME/webapps/middlewar/WEB-INF/lib/*.jar"