Java Forum / First Aid / June 2008
How come I can't seem to load a jar file successfully?
Jim - 23 Jun 2008 14:39 GMT I'm probably going to kick myself, but here's what's happening.
The referenced jar has the AsyncTimeoutException class.
jim@blackie:~/panel$ jar tf /opt/jdk1.5.0_15/jre/lib/ibmaio.jar | grep AsyncTimeout com/ibm/io/async/AsyncTimeout.class com/ibm/io/async/AsyncTimeoutException.class
However for some reason my program doesn't see it. Why? jim@blackie:~/panel$ java -classpath /opt/jdk1.5.0_15/jre/lib/ibmaio.jar -jar /home/jwl/panel/dist/lib/PanelProbe-20080623.jar Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/io/async/AsyncTimeoutException at com.fayettedigital.panelprobe.main.PanelProbe.testGECom(Unknown Source) at com.fayettedigital.panelprobe.main.PanelProbe.main(Unknown Source)
Thanks, Jim.
Lew - 23 Jun 2008 14:59 GMT > I'm probably going to kick myself, but here's what's happening. > [quoted text clipped - 14 lines] > at com.fayettedigital.panelprobe.main.PanelProbe.main(Unknown > Source) When you invoke 'java' with the '-jar' option it ignores the '-classpath' option and takes all its classpath from the target JAR manifest, in this case that of PanelProbe-20080623.jar.
Unless ibmaio.jar came with the JDK distribution itelf, it does not belong in /opt/jdk1.5.0_15/jre/lib/. That directory is for the libraries that make up the Java platform per se.
When using a tool like the 'java' command, it is best to RTFM: <http://java.sun.com/javase/6/docs/technotes/tools/solaris/java.html>
> -jar > When you use this option, the JAR file is the source of all user classes, > and other user class path settings are ignored. This is a subtle point and one which has burned all of us. The reason requires further digging in TFM: <http://java.sun.com/javase/6/docs/technotes/guides/jar/index.html> for starters.
We want to know if we're ignoring the classpath, how the heck do we tell our app where the heck things are, eh?
The answer, my friend, is blowing in the manifest: <http://java.sun.com/docs/books/tutorial/deployment/jar/manifestindex.html> Yay! A tutorial.
We set the entry point, i.e., who's got the main()? <http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html>
and co-deploy the ibmlmao (substitute your name here) JAR(s) *in the same directory as the app JAR*.
The manifest specifies the class path in the 'Class-Path: ' directive. <http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html>
Class-Path: ibmlmao.jar
The path is relative to the location of the app JAR.
 Signature Lew
Jim - 23 Jun 2008 21:00 GMT >> I'm probably going to kick myself, but here's what's happening. >> [quoted text clipped - 54 lines] > > The path is relative to the location of the app JAR. OK thanks. I also had to add the libibmaio.so to a directory in the java.library.path which for some reason doesn't include normal libary paths.
Lew - 24 Jun 2008 00:45 GMT > OK thanks. I also had to add the libibmaio.so to a directory in the > java.library.path which for some reason doesn't include normal libary > paths. That is something very non-Java-esque; there must be some JNI going on there.
So is that ibmlmao.jar or whatever represent part of the Java platform itself, because that's where you said you had it before, which seems like a bad idea, but maybe you have a good reason for it.
 Signature Lew
Jim - 24 Jun 2008 12:50 GMT >> OK thanks. I also had to add the libibmaio.so to a directory in the >> java.library.path which for some reason doesn't include normal libary [quoted text clipped - 6 lines] > itself, because that's where you said you had it before, which seems > like a bad idea, but maybe you have a good reason for it. I don't quite understand what you are saying. The packge is IBM's asynchronous I/O. It is a zip file with separate jar and libibmaio.so (and libibmaio.dll for windows) files, along with some documentation. When I printed out java.library.path I noticed it did not include any of the normal system libraries, /lib, /usr/lib, etc. so I just copied into one of the listed java library paths and it worked. That was after I include the jar file in my project as you suggested earlier.
When I printed out the java.library.path it displayed:
/opt/jdk1.5.0_15/jre/lib/i386/server:/opt/jdk1.5.0_15/jre/lib/i386:/opt/jdk1.5.0_15/jre/../lib/i386:/usr/lib/xulrunner-addons
So did that answer your question?
Thanks, Jim.
Lew - 24 Jun 2008 13:26 GMT >>> OK thanks. I also had to add the libibmaio.so to a directory in the >>> java.library.path which for some reason doesn't include normal libary [quoted text clipped - 12 lines] > When I printed out java.library.path I noticed it did not include any of > the normal system libraries, /lib, /usr/lib, etc. so I just copied into It shouldn't. The 'java.library.path' is not for "normal system libraries".
> one of the listed java library paths and it worked. That was after I > include the jar file in my project as you suggested earlier. [quoted text clipped - 4 lines] > > So did that answer your question? My question was whether this IBM JAR is inherently part of the Java platform, or if it's a regular library.
You had indicated that its location is /opt/jdk1.5.0_15/jre/lib/ibmaio.jar. That directory, /opt/jdk1.5.0_15/jre/lib/, is for Java, not for third-party libraries.
Since I am not familiar with that JAR as a part of Java, I questioned why it is in that directory.
 Signature Lew
Jim - 25 Jun 2008 01:46 GMT > My question was whether this IBM JAR is inherently part of the Java > platform, or if it's a regular library. [quoted text clipped - 5 lines] > Since I am not familiar with that JAR as a part of Java, I questioned > why it is in that directory. Neither the jar nor the dynamic load library, (.so file) are a part of the java distro. The package is distributed by IBM independently. The reason that jar was there was because I haven't found the documentation for how to handle external jars yet, or hadn't when I wrote that. I now know, thanks to you, that it belongs in my project and distributed with my jar or war or ear or whatever I use to run. At least I think that's what you said.
Now as far as the .so file goes, since java.library.path doesn't point to any system library paths, I just arbitrarily chose one to put the .so file. Probably wrong but it works. Google seems to say that I could have used a LD_LIBRARY_PATH environment variable to specify it too, but I have no idea how to add an environment variable to Eclipse and the eclipse news group responses to questions are spotty at best, so I went with what works. I'll fix it if and when I can find the right answer to the question of "where does it belong". I'm fairly sure it does not belong in my .jar file.
Thanks, Jim.
Roedy Green - 24 Jun 2008 02:14 GMT >I'm probably going to kick myself, but here's what's happening I don't think grep is the ideal tool to see what is in jar. Try using jarlook. See http://mindprod.com/products1.html#JARLOOK
 Signature
Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Lew - 24 Jun 2008 02:37 GMT >> I'm probably going to kick myself, but here's what's happening > > I don't think grep is the ideal tool to see what is in jar. Try using > jarlook. See http://mindprod.com/products1.html#JARLOOK Or WinZip for windows, or various archivers in Linux, or 'jar' just about anywhere.
$ jar -tf jarfile.jar META-INF/ META-INF/MANIFEST.MF com/ com/lewscanon/ com/lewscanon/eegee/ com/lewscanon/eegee/Example.class
 Signature Lew
Jim - 24 Jun 2008 11:35 GMT >>> I'm probably going to kick myself, but here's what's happening >> [quoted text clipped - 11 lines] > com/lewscanon/eegee/ > com/lewscanon/eegee/Example.class Perhaps you missed the entire command?
jar tf /opt/jdk1.5.0_15/jre/lib/ibmaio.jar | grep AsyncTimeout
I refuse to agree with anyone that thinks that's a bad thing to do, given my previous posting.
Jim.
Lew - 24 Jun 2008 13:26 GMT >>>> I'm probably going to kick myself, but here's what's happening >>> [quoted text clipped - 18 lines] > I refuse to agree with anyone that thinks that's a bad thing to do, > given my previous posting. My answer was an endorsement of your approach.
 Signature Lew
Jim - 26 Jun 2008 15:36 GMT Sorry, that was in response to another comment, not yours. I wasn't clear.
JIm.
> My answer was an endorsement of your approach. Roedy Green - 24 Jun 2008 14:17 GMT >I refuse to agree with anyone that thinks that's a bad thing to do, >given my previous posting. I thought you were scanning for the element names which are uncompressed inside the jar.
 Signature
Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Jim - 24 Jun 2008 11:33 GMT >> I'm probably going to kick myself, but here's what's happening > > I don't think grep is the ideal tool to see what is in jar. Try using > jarlook. See http://mindprod.com/products1.html#JARLOOK Why not? I didn't want to flood the group with unnecessary information which could hide what I really wanted to demonstrate.
You'll never convince me that jar tf xxx.jar | grep something is a bad thing. Especially since I don't even have jarlook installed.
Jim.
Roedy Green - 24 Jun 2008 14:18 GMT >Especially since I don't even have jarlook installed. the link was the download. You have been successful with jar.exe flags, so never mind.
 Signature
Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Mark Space - 24 Jun 2008 17:41 GMT >> Especially since I don't even have jarlook installed. > > the link was the download. You have been successful with jar.exe > flags, so never mind. Those jar.exe flags are pretty easy to manipulate, for the most part. Listing the contents of a jar file requires a very easy to remember combination of two flags. Whereas jarlook requires that I remember the path to jarlook, and do a lot more typing too. "java -jar C:\path\to\file\jarlook.jar" and then add the arguments to jarlook, this is not really easier than just the jar command.
I don't mean to pile up on you Roedy, just trying to explain why jarlook isn't a great utility for replacing the basic jar utility. And grep is available everywhere. I have it on my windows box courtesy of Cygwin, and if I set the default windows path to point to the Cygwin binaries, I have grep available in the regular Window's command prompt too.
Now if jarlook did other things besides what jar did, and if jarlook was easier to add to the command line path with out the full java -jar command, that would be something I could get behind.
John B. Matthews - 24 Jun 2008 21:43 GMT > >> Especially since I don't even have jarlook installed. > > [quoted text clipped - 17 lines] > easier to add to the command line path with out the full java -jar > command, that would be something I could get behind. I keep a few command-line jars in ~/bin with eponymous scripts to save typing:
#!/bin/sh java -jar ~/bin/<some>.jar "${@}"
As it's a common cause of jar problems, here's a class I use to examine the manifest without having to extract it. It might make a good addition to JarLook:
import java.util.Map; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest;
/** * Display the manifest of a jar file. * @author John B. Matthews */ public class Manifesto {
public static void main(String[] args) { if (args.length < 1) showHelp(); else for (String name : args) try { System.out.println("Manifest: " + name); JarFile jar = new JarFile(name); Manifest manifest = jar.getManifest(); if (manifest != null) showMap(manifest.getMainAttributes()); } catch (Exception e) { System.out.println(e.getMessage()); showHelp(); System.exit(1); } } private static void showMap(Attributes map) { for (Map.Entry<Object, Object> e : map.entrySet()) System.out.println(e.getKey() + ": " + e.getValue()); } private static void showHelp() { System.out.println( "Usage: java Manifesto <jarfile> [<jarfile>]"); } }
For amusement, try and guess what happened when I (carelessly) named the class Manifest. :-)
 Signature John B. Matthews trashgod at gmail dot com home dot woh dot rr dot com slash jbmatthews
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|