0

We are having a module which contains log4j.properties and other files in it. And there is a separate module which is dependent on the 1st module(Realign). So we had made the 1st module as a jar file and placed it in the WEB-INF/lib folder of the second module(Reasign). We are running the modules in Liberty server. But still we are getting the File Not found exception as below,

log4j:ERROR Could not read configuration file
[file:/metlife/runtime/installed/wlp/usr/servers/bobr/apps/expanded/bobr.ear/BOBReassignmentWeb.war/WEB-INF/lib/Realignment.jar!/r_resources/log4j.properties].
[9/12/18 8:28:51:591 EDT] 000002de SystemErr                                                    R java.io.FileNotFoundException: 
file:/metlife/runtime/installed/wlp/usr/servers/bobr/apps/expanded/bobr.ear/BOBReassignmentWeb.war/WEB-INF/lib/Realignment.jar!/r_resources/log4j.properties (No such file or directory) 
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
Venkatesh
  • 31
  • 1
  • 7
  • Can you try using classloading semantics to load the log4j.properties instead of loading it as a file? It looks like you are auto-expanding the app, but that ends up putting the app files in different locations - easier to load for Liberty, but not always easy to find for users. I'd suggest either disabling auto-expansion or looking up the log4j.properties file via something like: URL url = myAppObject.getClass().getResource("r_resources/log4j.properties"); HTH, Andy – Andy McCright Sep 13 '18 at 17:08
  • PropertyConfigurator.configure(this.getClass().getResource("/r_resources/" + RealignBeans.LOG4J_PROPERTIES).getPath()); System.out.println("******************Loading log4j Realign****************"+this.getClass().getResource("/r_resources/" + RealignBeans.LOG4J_PROPERTIES).getPath()); PropertyConfigurator.configure(this.getClass().getResource("/r_resources/" + RealignBeans.BWLOG_CLIENT_BOB_LCF).getPath()); System.out.println("******************Loading log4j Realign****************"+this.getClass().getResource("/r_resources/" + RealignBeans.BWLOG_CLIENT_BOB_LCF).getPath()); – Venkatesh Sep 14 '18 at 13:56
  • The above one is our current code which is throwing error now – Venkatesh Sep 14 '18 at 13:56
  • And when we changed the autoexpand property as "false", we are getting file not found for all configurations. Whether we can remove the autoexpand property from the server.xml? – Venkatesh Sep 14 '18 at 14:11
  • Ah - the problem is that the PropertyConfigurator.configure() method has a String parm (the path to the config file), instead of a URL. A URL would be better, because it handles the case where the file is inside an archive (JAR, WAR,...), where a String indicating a path on the file system cannot - note the "!" after Realignment.jar in the path. This indicates where the file is inside the jar. If the configurator can accept a URL, then pass in the URL returned from getResource. If not, you might consider putting the resources in a shared lib where it can be read directly on the file system. – Andy McCright Sep 14 '18 at 22:14
  • Could you please help me more on how to do this? – Venkatesh Sep 17 '18 at 09:20
  • More info in my answer. If you have further questions or it doesn't work, please let me know. – Andy McCright Sep 20 '18 at 22:28

1 Answers1

1

It looks like your PropertiesConfigurator class is taking a file path (as a String). If you used a URL instead, I think that would work - that way, you would get a JAR URL which includes the path to the JAR (or WAR, EAR, etc.) archive and the path inside the JAR. If you have control over the PropertiesConfigurator code, then I would recommend changing it so that it loads the file via URL.

If that is not an option, then you could extract the properties files and put them on the file system directly. For example, you could create a directory in your server directory (for an example, we'll call it log4jProps). Then you could create a shared library in your server config (server.xml) like this:

<library id="log4j.props">
  <fileset dir="${server.config.dir}/log4jProps" includes="r_resources/*properties"/>
</library>

then update your application configuration to use this library as a common shared library:

<application id="myApp" name="myApp" location="myApp.war"...>
  <classloader commonLibraryRef ="log4j.props" />
</application>

For good measure, you should probably remove the properties file from your application archives - that way they won't be loaded from there, and then throw off the PropertiesConfigurator like it is now.

Hope this helps, Andy

Andy McCright
  • 1,273
  • 6
  • 8
  • The log4j error has been resolved Andy. Now we are getting java.lang.NoClassDefFoundError: org.hibernate.Session. The respective jar is placed in the WEB-INF/lib folder. But still we are getting this error. we added the jar in MANIFEST.MF also. But it is also in vain – Venkatesh Sep 21 '18 at 12:43
  • This sounds like a separate issue, so I would recommend opening another question on SO. Please include the full stack trace of the error and include the name of the JAR that contains `org.hibernate.Session`. It might also help to see other JAR files in the WEB-INF/lib directory in case the hibernate JAR is missing a dependency. HTH, Andy – Andy McCright Sep 21 '18 at 13:19