Where to put a .jar file in an exploded EJB module

£可爱£侵袭症+ 提交于 2019-12-13 04:38:27

问题


I am deploying a JMS module to work alongside a servlet application. While I am writing (and testing and rewriting) my module, the module is not stored in a JAR file; it is in an exploded directory doubling as an Eclipse project directory. (In the production environment, it will be in a jar.)

My JMS module does logging with log4j. My question is: where do I put the log4j.jar file so my EJB can find it? I tried various locations, including a directory named lib/, but nothing seemed to work. (I could tell Eclipse to find it in any of half a dozen places.) I eventually resorted to putting it in the server domain lib directory (domains/my_domain/lib), which worked for my JMS module, but messed up my servlet module's access to the data sources - I kept getting a NotSerializableException.

If it makes any difference, I'm using Eclipse (Juno) to develop, Weblogic 10.3.5 to run and test.

Thanks.


回答1:


In fact there is not so much difference whether your jar is exploded or not. The main thing is that you need your libraries on classpath. You need to specify jar location in your manifest file:

Class-Path: lib/log4j.jar

You can use this Oracle documentation for reference.




回答2:


My working solution (which works for Weblogic, but probably is not portable), is to add a line to the %DOMAIN_HOME%\startWebLogic.cmd script in the domain root directory:

set PRE_CLASSPATH=C:\${path}\log4j.jar

where ${path} points to an external directory (within my home directory). That seems to work without breaking anything else. I did try placing the JAR within the $DOMAIN_DIR/lib directory, but that ruined my primary servlet application running on that same server; for some reason, a data source could suddenly not be de-serialized properly.

I'd been hoping there was a semi-standard place to put JARs, as in the WEB-INF/lib directory for servlets, and that was the answer I was really looking for. But it seems such a place does not really exist.

Edit: After looking at this answer again (and having the same problem, again), here is the better answer. The Class-Path: in the MANIFEST.MF file is relative to the root directory of the exploded jar. So:

  1. If log4j.jar is in the same directory as the JAR's root directory (not in the JAR's root directory), you would use Class-Path: log4j.jar.
  2. If log4j.jar is in the JAR's root directory (e.g. as a sibling to META-INF), you would use (if your JAR is in directory JarRoot): Class-Path: JarRoot/log4j.jar.
  3. I tried using an absolute path, e.g. C:/home/Menachem/work/libs/log4j.jar, but it didn't work. I didn't try again with backslashes, once I'd (finally) worked out rules #1 and #2 properly.

I hope this is useful to someone else besides me...



来源:https://stackoverflow.com/questions/18619487/where-to-put-a-jar-file-in-an-exploded-ejb-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!