LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Where to find the JARs for javax.swing.* and java.awt.* (http://www.linuxquestions.org/questions/programming-9/where-to-find-the-jars-for-javax-swing-%2A-and-java-awt-%2A-693976/)

jlinkels 12-30-2008 09:39 PM

Where to find the JARs for javax.swing.* and java.awt.*
 
I am trying to recompile a JAVA project with a few hundreds of files. Once I am able to recompile, I can add that three lines of code I need, and then the application does what is has to do.

The source files import a lot of classes from javax.swing.* and java.awt.* (and maybe a few more)

I have a lot of JARs on my system after I installed the packages which I thought were necessary. But at least I think the JAR file name should reflect something like "swing" or "awt". I understand there is no such thing like javax.jar.

These are the packages I installed by now as a result from some heavy google actions and recommendations:

openjdk-6-jdk
openjdk-6-jre
openjdk-6-jre-headless
openjdk-6-jre-lib
openjdk-6-source
sun-java6-jdk

I also installed the GNU classpath package, which claims to offer a full set of classes needed for JAVA development. But I only see a lot of .so files installed, no JARs.

There are also recommendations as to install J2SE, but on Sun's site I but I always end up on pages which offer downlaods for Java SE, Java EE, Glasfish and whatnot.

java.awt and javax.swing seem to be the most common libraries for building X applications, but where to find them. And maybe some other very common packages.

jlinkels

gsl 12-31-2008 12:41 AM

Quote:

The source files import a lot of classes from javax.swing.* and java.awt.* (and maybe a few more)
Try looking for a jar called "rt.jar" ("rt" short for "runtime", I think). In a default Java installation, this jar contains most of the core java classes, including java.awt & javax.swing. I've never used GNU Classpath so I don't know how it organises things.

Geoff.

knudfl 12-31-2008 09:46 AM

Java 2SE = java SE ( j2 SE is just an older term )
http://java.sun.com/javase/downloads/index.jsp
> >
https://cds.sun.com/is-bin/INTERSHOP...-CDS_Developer
and get 'jdk-6u11-linux-i586-rpm.bin'
....

jlinkels 12-31-2008 10:18 AM

OK, I have found /usr/share/jdk1.6.0_11/jre/lib/rt.jar

Listing the contents gives a comforting look with a few thousands of classes, including javax/swing and java/awt.

I assume I have to add /usr/share/jdk1.6.0_11/jre/lib to the CLASSPATH in order to find this lib during compile time.

Thanks, I would not have been able to find this myself.

jlinkels

gsl 12-31-2008 07:04 PM

Quote:

I assume I have to add /usr/share/jdk1.6.0_11/jre/lib to the CLASSPATH in order to find this lib during compile time.
In a proper Java setup (which I assume yours is) you should never need to include the core jars on the classpath. The javac compiler should know how to find all the jars in the jdk*/jre/lib and jdk*/lib directories. Your classpath should only need to include your own Java sources and any external (non-core) jars you might be using.

Geoff.

jlinkels 01-02-2009 08:46 PM

Quote:

Originally Posted by gsl (Post 3392991)
In a proper Java setup (which I assume yours is) you should never need to include the core jars on the classpath. The javac compiler should know how to find all the jars in the jdk*/jre/lib and jdk*/lib directories. Your classpath should only need to include your own Java sources and any external (non-core) jars you might be using.
Geoff.

No it doesn't, really. More specifically you have to tell javac where it can find the classes. The location of rt.jar is not standard and depending on the jdk version. This said, I would have been nice if Debian at the installation of the JDK would have set the classpath, but it had not.

Some more observations:

I settled for using ant tool to compile and build this source tree. (http://ant.apache.org/). It was quite straightforward (well, kind of), but using the example build.xml got me going very quickly.

Once I got the hang of looking up jars on the internet, I was able to find about 10 more jar files which had to be added to the libraries. It is not difficult, but you have to know what you are looking for. If you are totally blank, it is overwhelming, but after that it is OK. BTW, CLASSPATH is not a path, it has to be a list of all JAR files which you want to include in the compilation, so youhave to specify /usr/share/jdk6/*.jar and not /usr/share/jdk6. CLASSPATH gets very large if you have enough classes!

In the source tree there was a part which interfaced with SQL and had a number of classes derived from java.sql.preparedstatement and java.sql.callablestatement, which were TraceCallableStatement, TraceConnection, TracePreparedStatement, and TraceStatement. There were a huge number of abstract methods which were not overrided in these derived classes. Perhaps the developer at that time compiled against JDK 1.0 or 1.1. I went as low as 1.2, but there was still the problem of these abstract methods. I ended up to add the methods for each not overrided abstract class, which eventually were over one hundred. (Yes, I learned that Java allows to define multiple methods with different parameter lists, and they all have to be overrided)

The problem here was that Javac would only give a few error messages per file, I could not figure out why only so few. I have compiled at least a hundred times, and every time 3 or 4 errors would be stated. Well, after twenty times solving errors and adding methods from Preparedstatement and CallableStatement and TraceCallableStatement, TraceConnection, TracePreparedStatement, and TraceStatement the Traces, Statement and Prepareds became pretty big mess, especially if you take into account that in one object setNClob (int i, Clob x) had to be added in 4 variation and in one other setNClob (String i, Clob x) and then getNClob oh no, it was setBlob, no setNBlob, oh that was TraceCallableStatement no, that was setBlob, no that was setBlob (int i, Reader x), no that was getClob or was it getClob, no that was in TracePreparedstatment...

WHAT DID I DO WRONG HERE AND WHY WAS I FOUR DAYS ADDING THOSE METHODS TO THE CLASSES?

Eventually I had all methods added, and only THEN the compiler started to complain about missing return statements, which I solved my called the ancestor, and when that was solved, I had to add the ThrowSQLExceptions that I forgot and when that was finished the compiler complained about the function isWrapperFor which was not overrided and unWrap alike but those were no part of Preparedstatement and CallableStatement so I had to get them from Wrapper and when that was finished they did not throw SQLExceptions but something else and when I fixed that the compiler complained that some abstract methods were not overridden, and finally, yes, I have to admit, I forgot a semicolon.

I think it is better to get 400 compile errors at once than a hundred times four...

The good news is that suddenly, in the 123rd run ant would tell "Build completed succesfully" Just out of the blue. I had been down to 1 error many times before, but the next time it would give me another 3 or 4. This was soooo sweet. Ant let me create the jar file as well, even when compiling going up to jdk5 again, and as unbelievable as it is, the JAR file could actually be run, and even produced the same program as I had downloaded and run before.

Now ahead to adding those 3 lines...

jlinkels


All times are GMT -5. The time now is 07:06 PM.