I am getting compile errors "cannot resolve symbol" on several lines of code. I did reference my JAR file in the CLASS PATH. I don't know why when I unzip the JAR file the compiler sees the directory and subdirectory files fine. There must be something missing?
Hi Linda, Not sure about this, but I think jar file are place inside lib directory inside where you install SDK, and I thought classpath is to only to read .class files, but not .jar. if you have install the SDK in C:\j2sdk1.4.1_01\ then jar file should be place here: (thats how I did it) C:\j2sdk1.4.1_01\lib then set the path: path C:\j2sdk1.4.1_01\lib as well as any other sources your program depend, like the current directory (.), for example: .;C:\j2sdk1.4.1_01\lib hope this helps.
Actually Alex, you can place a jar file any place you desire. When you specify a directory in your classpath, the Java Runtime Environment (if running a program with the java command) or the Java Compiler (if compiling with the javac command) will only find classes that are in that directory. For jar files, you must specify the path to the directly to the jar file. An example may help� Given the following directory structure:
StartHere.class contains a main method and is not in a package.
Stuff.class is not in a package
SomeClass.class is part of the package com.foo (thus making its full name com.foo.SomeClass)
myLibary.jar contains the class com.bar.Utility (in a proper directory structure)
The application, launched via the StartHere class, uses all these classes
If I specify the command: java �classpath C:/dev StartHere The Java Runtime environment will find all the classes except those in the jar file, like com.bar.Utility. When a directory is specified in the classpath (whether as a switch argument or in the System/Environment CLASSPATH variable), the JRE/compiler only finds classed contained within that directory (since com.foo.SomeClass is the full name of that class, it is considered to be in the C:\dev directory even though the physical file resides in the directory C:\dev\com\foo because the JRE (or compiler in the case of javac) �knows� to append the package directories onto the classpath directory). If you need to use classes within a jar or zip file, you must specify the path to that jar or zip file like this: java �classpath C:/dev;C:/dev/myLibary.jar StartHere (on Unix or Linux, you would use a colon �:� delimited list and not a semi-colon delimited list). Now the JRE knows when looking for a class to look inside that jar file as well the directories listed. The same holds true for the compiler: javac �classpath C:/dev;C:/dev/myLibary.jar StartHere.java You can also specify relative paths. For example, if the current working directory is the C:\Dev directory, I can do this: C:\Dev> java �classpath .;myLibary.jar StartHere (The dot in the classpath list means current directory). This of course assumes your java (or javac) executable is in your system�s path. If not, you need to fully qualify it like this: C:\Dev>C:\j2sdk1.4.2_03\bin\java �classpath .;myLibary.jar StartHere -- Linda, If you are directly specifying the path to the jar file in your classpath and are having issues, there may be a problem with the jar file itself. Post the command you are using to compile with, the full error you get, and a table or contents of the jar file (i.e. the complete output of the command jar -tf jarName.jar). If you are creating the jar file yourself, post the command you are using to do so. With that info, someone should be able to help. [ March 03, 2004: Message edited by: Mark Vedder ]
Joined: Sep 24, 2001
Thank you both for replying. You are correct Mark. When I specified my JAR file in the C:\Java folder and compiled with your command, it knew to find the file in the current directory. I was bewildered when I set my classpath to look for the JAR file, it didn't find it. It wasn't until I re-booted my computer .. did it find the file. I am using Win98 and I thought typing "C:\autoexec.bat" would set it. Guess I was wrong. BTW, is there a DOS command I can type in to see all the compile errors? Basically if I have so many errors, it just scrolls and I don't get to see the first few errors.
In more recent Windows versions (NT, XP) there's an option to set the scrollback buffer size under the "Properties" menu of the DOS box. Set it to something big; I've used 4000 lines. Then you'll be able to scroll back and see the errors.
Linda, If you want to see the errors in windows 98 and don't want to go to a sophisticated IDE (Integrated Development Environment), use TextPad, available from textpad.com. With textpad, you can compile the java file you are editing with a ctl/1 keyboard action and your compile errors are listed in a separate scrollable window. Does not help much with runtime exceptions, because they will still appear in the DOS window, but then I use a file logging class for my exceptions to which I open another textpad window. Ed
The nice thing about Standards is that there are so many to choose from!