2

I have a ear deployment which contain several war. A common library is needed by these wars so a custom module is created. This library would somehow load the classes in the war (using class.forName() may be)).

However, it seems that the module is not able to get access to the classes in the war and keep throwing ClassNotFoundException upon deployment. Is there any configuration needed to expose the classes to be accessed by the module? I tried with those export=true settings on the module but get no luck with it.

The library I needed is DWR with spring FYI.

Quincy
  • 4,393
  • 3
  • 26
  • 40
  • Why you don't put the library inside `ear/lib` directory to share between wars? – Federico Sierra Jan 06 '15 at 14:13
  • That's a third party library and I presume it should be created as a module as good practice? – Quincy Jan 07 '15 at 01:12
  • It depends, the size of libraries or the requirements, for example if you need that your application can be deployed across different application servers it would be best to add dependencies inside the EAR. See http://stackoverflow.com/questions/8289813/best-practice-for-loading-3rd-party-jars-in-jboss-as7-standalone-deployment – Federico Sierra Jan 07 '15 at 02:04
  • So despite the practice thing, is it possible to achieve the result in the question? On the other hand, I tried and it only works if I move both the classes in war and the thirdparty lib to ear\lib. – Quincy Jan 07 '15 at 02:41
  • First check that is properly adding dependency to the module, I recommend using the `jboss-deployment-structure.xml` file inside the EAR. – Federico Sierra Jan 07 '15 at 02:58
  • 1
    In addition to the above, `Class.forName("org.foo.SomeClass")` will cause issues in modular classloading environments if the defining classloader doesn't have classloading delegation set up to the module that's holding the "org.foo.SomeClass" class. This problem is solved by using the `ClassLoader cl = Thread.currentThread().getContextClassLoader(); Class.forName("org.foo.SomeClass", true, cl)`. See https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.2/html/Development_Guide/sect-Use_the_Class_Loader_Programmatically_in_a_Deployment.html – Federico Sierra Jan 07 '15 at 02:59
  • Does it mean the module should be able to access the classes in ear if settings are correct? If so then the cause is probably the library itself not supporting wildfly. – Quincy Jan 07 '15 at 05:20
  • No, the dependency is from ear to modules, not modules to ear. Can you explain with more detail what you want to do? – Federico Sierra Jan 07 '15 at 19:28
  • I just want to set those third party libraries as jboss modules other then lib in the deployment. But it seems that only the classes in the deployment can access the modules classes and not the other way round. – Quincy Jan 08 '15 at 14:42

0 Answers0