0

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.

Menachem
  • 911
  • 7
  • 22

3 Answers3

2

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.

sermolaev
  • 975
  • 11
  • 23
  • It doesn't work. Especially as the link you posted contains a note saying that jars can't contain other jars. Here is a quote: _The Class-Path header points to classes or JAR files on the local network, **not JAR files within the JAR file** or classes accessible over internet protocols._ – Menachem Sep 09 '13 at 15:49
  • I didn't recommend you to put jar in another jar. Where did you see that? As it said in your own quote, **The Class-Path header points to classes or JAR files on the local network**. It's the same thing if you would use -classpath(-cp) flag. Why do you think it won't work? – sermolaev Sep 10 '13 at 03:32
  • As I understand, `MANIFEST.MF` is for JARs. This is not a JAR; it is an EJB in a directory. I can't put `log4j.jar` in my Project directory, as that would be effectively the same as in the JAR. so when you suggested `lib/log4j.jar`, what is that path relative to? Yes, it would be the same as using `-cp` - but how can I tell the server to add a directory to the classpath automatically and portably? -- BTW, I intend to post what I actually did as a separate answer. Thanks for your help, though. – Menachem Sep 10 '13 at 14:47
  • 1
    EJB can be packed in a jar, so in current context it **is** a jar. No matter, exploded or not. path to 'lib/log4j.jar' is relative to the path where your exploded directory is located. You need to put log4j.jar not **in**, but **near** your exploded directory. – sermolaev Sep 10 '13 at 16:35
  • Thank you. It finally worked properly. In your answer, you left out the detail of where the JAR should be located, and an explanation of what the `Class-Path` is relative _to_. I tested with a different but similarly designed JMS module, and it took me a few tries until I settled on `Class-Path: ../javalibs/log4j.jar`, which works. I also had to set up a new project (at least, a directory) to hold the JAR file in question. – Menachem Sep 11 '13 at 18:39
0

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...

Menachem
  • 911
  • 7
  • 22
0

Note that Oracle recommends that you package EJBs as part of an enterprise application.

Package section of Oracle docs

Yuri P.
  • 11
  • 1