LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-30-2008, 08:39 PM   #1
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,165

Rep: Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506
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
 
Old 12-30-2008, 11:41 PM   #2
gsl
LQ Newbie
 
Registered: Jun 2007
Location: Melbourne, Australia
Distribution: Slackware
Posts: 24

Rep: Reputation: 5
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.
 
Old 12-31-2008, 08:46 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 13,947

Rep: Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602
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'
....
 
Old 12-31-2008, 09:18 AM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,165

Original Poster
Rep: Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506
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
 
Old 12-31-2008, 06:04 PM   #5
gsl
LQ Newbie
 
Registered: Jun 2007
Location: Melbourne, Australia
Distribution: Slackware
Posts: 24

Rep: Reputation: 5
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.
 
Old 01-02-2009, 07:46 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,165

Original Poster
Rep: Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506
Quote:
Originally Posted by gsl View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java and Jars ? EAD Programming 6 12-31-2006 02:10 PM
java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit artemis8543 Linux - Newbie 4 05-16-2006 08:38 PM
what is import javax.swing.*; Dutchman Programming 4 06-16-2005 10:12 AM
getting javax.swing.* to appear student04 Programming 8 10-05-2004 10:06 AM
javax.swing doesn't work israel Programming 4 02-19-2004 11:59 PM


All times are GMT -5. The time now is 04:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration