Kiran Mohan
Kiran Mohan

Reputation: 3006

WildFly + java Preferences cannot find custom preferences class in classpath

I am deploying an EAR with the below structure to Wildfly 9.0.2

my.ear  
  |-my.sar    (it is a SAR archive)
  |-lib
     |-myPreferencesImpl.jar

I am able to load the classes in lib/myPreferencesImpl.jar from my.sar (like class.forname(com.my.PreferencesFactory) directly. However, java.util.prefs.Preferences.factory is not able to load com.my.PreferencesFactory. I am passing Djava.util.prefs.PreferencesFactory=com.my.PreferencesFactory as command line parameter during WildFly startup.

Below is the exception thrown.

 Caused by: java.lang.ClassNotFoundException: com.my.PreferencesFactory from [Module "org.jboss.as.jmx:main" from local module loader @76a3e297 (finder: local module finder @4d3167f4 (roots: /CSA_wildfly/wildfly/modules,/CSA_wildfly/wildfly/modules/system/layers/base))]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at java.util.prefs.Preferences.factory(Preferences.java:254)

Please help me fix this.

UPDATE:
I finally fixed by migrating the startup service using JMX Service to a @Singleton + @Startup EJB. No other changes were required.

Upvotes: 1

Views: 238

Answers (1)

Pradeep Pati
Pradeep Pati

Reputation: 5919

When you pass the arg Djava.util.prefs.PreferencesFactory=com.my.PreferencesFactory in command line, Wildfly is going to look for the class in the classes available to it, which is provided by way of modules . During the Wildfly bootup, it's not even going to know that there is a application with that class present, neither can it provide the same class to other deployments on the same container. So if you want the command line arg to work, make sure the deploy the Factory implementation as a Wildfly module.

Upvotes: 2

Related Questions