3

My project structure is the following. Server is Glassfish 4. IDE - netbeans 7.4. Project temp is used by project a.

EAR
 + lib/temp.jar
 + a.war

Temp.jar contains core classes. They are used by war. Temp.jar doesn't import any files from war, and it must know about war nothing. But, temp.jar has classes that creates instances of war classes by reflection (according to xml file). Here I get ClassNotFoundException. How can it be fixed? Is it possible to fix or I have wrong project structure?

Note: I didn't put temp.jar in a.war as there can be different war files that can use this jar.

Ashish
  • 1,943
  • 2
  • 14
  • 17
  • Is there an `application.xml` file? Does it contain a `` element? – Nikos Paraskevopoulos Nov 13 '13 at 12:46
  • @Nikos Paraskevopoulos Thank you for you time. No, there is no any application.xml –  Nov 13 '13 at 15:23
  • I think according to specs your setup *should* work. However could you create a `META-INF/MANIFEST.MF` file in your WAR (under the content root, i.e. side-by-side with `WEB-INF`) and place an entry as follows: `Class-Path: lib/temp.jar` – Nikos Paraskevopoulos Nov 13 '13 at 15:36
  • @Nikos Paraskevopoulos Result is the same. War classes can reach jar classes without problem. Jar classes can't reach war file. –  Nov 13 '13 at 15:51
  • My failure!!! I did not notice the exact question (use classes of *WAR* from *JAR*). Still, one **dirty** way (have never tested, be warned) is to place a similar Class-Path entry in the manifest of the *JAR*: `Class-Path: ../a.war`. But I would recomend placing the shared classes in *another JAR* and referencing that from both the WAR and the JAR. – Nikos Paraskevopoulos Nov 13 '13 at 15:58
  • @Nikos Paraskevopoulos Thank you. This war keeps the files which belong only to it. It will ruin all the application structure. I asked more correct question http://stackoverflow.com/questions/19958573/glassfish4-access-isolation-settings-for-classes-in-modules-and-libraries-for –  Nov 13 '13 at 16:07
  • @Nikos Paraskevopoulos I found the answer and published it. –  Nov 13 '13 at 19:45

2 Answers2

3

I found the answer.

If we put jar into ear/lib folder then the classes in it can be accessed but they can't access the classes out of lib (in this case there is no need to add something to manifest file of war).

If we put jar in root of ear or in any other folder ear/bum than the classes of these jar can access war classes.

So I conclude, that /lib is monodirectional, any other are bidirectional.

Hope it will save someone a lot of time.

2

Add jar file to the you lib folder. Change MANIFEST.MF and add the particular jar path to Bundle-ClassPath.

That worked for me.

praveen
  • 21
  • 1