I am using JBOSS 7
In my custom jar I am implementing an Interface. The interface is in a jar packaged with ECM.ear file. Unless I put my custom jar inside the web-inf/lib folder (of the war file located in ear file) I am getting ClassNotFoundException w.r.to the interface.
I created a module for my custom jar but I don't how to set up a dependency with ear file. I copied the jar containing the interface say mdm.jar and placed it in the module and also added an entry in the resource root of module.xml. After restarting I am getting ClassNotFoundException for the classes referred by mdm.jar, which arein ear file.
How to achieve this dependency?
Thanks,
Raghu
JBOSS 7 needs you to place the packaged jar files in the lib folders of your web-inf/lib or the ear/lib cos of the Class Loading Precedence that JBOSS server follows.
Alternatively you could load it as a module, but you need to specify any addition of this kind outside of JBOSS default supplied modules using your MANIFEST file or jboss-deployment-structure.xml
This link should provide you more insight on what would suit you best.
Hope it helps.
Related
I am trying to migrate my application server from JBoss4 to Wildfly 9. The structure of my war is
myWar.war
- WEB-INF
-lib
-jar1
-jar2
When I deploy this war in Wildfly, classes inside these jars are not accessible (ClassNotFoundException).
After reading more about Wildfly, I learnt that classloading is changed in Wildfly and dependencies need to be explicitly mentioned in file jboss-deployment-structure.xml or in Manifest.mf
I am a little confused and have 2 questions -
Is it required to specify this dependency in
jboss-deployment-structure.xml or manifest.mf (as the jars within
the war's lib) ?
If yes, how to exactly specify this dependency of jars ? I tried some ways of mentioning dependencies by their jar names/package
names in jboss-deployment-structure.xml, etc but with no luck
(everytime I get missing dependencies or module not found exception,
etc)
Do I have to create a module under Wildfly's modules directory also ? But these jars are dynamically created and packaged in war file with my build scripts, so I cannot place jars under modules folder (like quartz or mysql jars) as these are not static.
Please help.
jars inside the war's lib folder don´t need to be declared in MANIFEST.MF or jboss-deployment-structure.xml.
Those files are used to declare dependencies to wildfly modules (for example jdbc driver, cxf dependencies, etc).
Are you sure your ClassNotFoundException comes from jars included in your war's lib folder? You don´t need to do anything special to load classes from the lib folder of your war.
Wildfly 9 do expect a particular-way structured web-archives. From the war structure every thing looks fine. Do re-check the war structure is in conformance with Widfly 9. Right structure should be like :
myWar.war
---WEB-INF
------- lib
---- Jar 1
---- Jar 2
-------- classes
---- Your classeses here
-------- web.xml
In JBoss, if you have an ear archive file, the way to tell the environment the place
of the lib folder, where it can find the library files, is the application.xml file.
Now I splitted the ear file into separate .war and .jar files. I do not have an ear folder anymore, so I deploy the war and jars directly in JBoss.
In the war archive I have the html and servlet files. In the jar archive I have the bean files. Now the library files are just needed by the java beans, not by the servlets.
So I need a folder in the .jar file to put the lib files and a way to tell the system the place of this folder.
If you want to have your jar libraries inside an ejb-jar: you can't, the standard specification doesn't allow you to have a jar inside another jar. Maybe some vendors provide specific solutions for that, but those are not standard. The standard solution would be to place all the related jars inside an ear. What you can do, and it's standard, is placing library jars inside the WEB-INF/lib directory of a war; but ejb-jar don't provide a similar structure.
How can I include external jar file in my ejb3 jar file? There is one external jar project with all helper classes and manifest.mf file. Now I have this jar in my classpath in eclipse. But when eclipse build the ejb-jar I want it to include this external jar file so in Application server when my ejb loads and run it can use classes in external jar. Right now I am adding a reference in Manifest.mf for ejb-jar, still when eclipse build the ejb-jar it is not packaging this external jar and during runtime I am getting ClassNotFoundException.
Can somebody please give me an example how to achieve this? I am using Eclipse 3.6 and EJB3
You have to create ear or war deployment and include your ejb.jar and a third-party.jar into it. Then deploy it to jboss
I found a solution.
Method 2 Worked for me. the tutorial uses Rational, but I assume Eclipse will be similar.
http://www.ibm.com/developerworks/rational/library/07/1211_schrag/index.html
check it out.
We have ear that depends on war file.
We use web configuration.
I put war file to <jboss_home>/server/web/deploy directory.
And I put ear file to <jboss_home>/server/web/deploy/deploy.last directory.
But ear starts prior to war.
Why?
I use a similar configuration to what you describe, though I put all the apps I want to deploy first in deploy/myapps and all the ones to deploy afterwards in deploy/myapps.last. This works correctly for me on JBoss 5.1.2.
Although I can't explain why it isn't working for you, I can offer an alternative solution. You can make the EAR declare a dependency on the WAR and JBoss will then ensure the WAR is deployed first.
First, add a file called aliases.txt into the META-INF directory of your WAR. This file should just contain a single line with an arbitrary name / identifier for your WAR. For example, if you have mywebapp.war, your META-INF/aliases.txt file could contain 'mywebapp'. It just needs to be something that won't clash with any other aliases declared by other apps deployed on the same server.
Next, add a jboss-dependency.xml file to the META-INF directory of your EAR, containing the following (subsituting 'mywebapp' for the alias you created above):
<dependency xmlns="urn:jboss:dependency:1.0">
<item whenRequired="Real" dependentState="Create">mywebapp</item>
</dependency>
This should ensure the WAR is deployed before the EAR.
Also, if you try to deploy the EAR without the WAR being present, JBoss will log a clear deployment error message telling you about the missing dependency.
i am wondering what is use of jbossall-client.jar ?
Up to JBoss version 4.2.3 these file contains client code for application.
But since JBoss 5.0 these file contains only dependences against other libraries from server client directory. If you want use it you must put also other jar file on in the same directory as jbossall-client.jar. These is excerpt from readme.txt file from jbossall file:
This jar file contains a classpath reference to various client jar files used by jboss client applications.
Each of the jar files in the following list must available in the same directory as the jbossall-client.jar, Otherwise they will not be found by the classloader.
In readme.txt you can also find the list jar files against which jbossall-client has dependencies.
It's a bundling of all JBoss client code into a single JAR, for those who don't want to bother with selecting the individual smaller JARs.