Java GUI Tutorial

Found a nice java tutorial  on java swing here. This is a sterling bit of work from Chua Hock-Chuan (ehchua@ntu.edu.sg) – am guessing Singapore ? His home page is like a programming cookbook, see here. Was looking to see how to re-theme a java gui. Love these diagrams of his ( thanx Chua ! ) so we can see the swing class structures and inheritance.

Swing Container Class Diagram

 

Swing_JComponentClassDiagram

 

 

 

 

 

Also found this post on gui themes, though it looks to be older and may not apply to newer java 1.6+ environments.

And if you need a java mouse motion listener example, check this out from Ilias Tsagklis.

Java on IBM System/i and AS/400

JT400We often need some help in our java development when we work with IBM mid-range systems. The jt400 toolkit is a great set of support features. Get your download from sourceForge of it here. The latest version, JTopen 7.9, was released 01/03/2012. For more details, see their sourceForge website here. It has a variety of support features we need when dealing with OS/400 internals. These include :

  • Database — JDBC (SQL) and record-level access (DDM)
  • Integrated File System
  • Program calls (RPG, COBOL, service programs, etc)
  • Commands
  • Data queues
  • Data areas
  • Print/spool resources
  • Product and PTF information
  • Jobs and job logs
  • Messages, message queues, message files
  • Users and groups
  • User spaces
  • System values
  • System status

Here is a list of FAQ from  website found here. These are mostly related to Toolbox for Java and JTOpen. IBM also offer a forum for the Toolbox here. It appears active as of march, 2013, so we might find some help on offer with tricky bits 🙂

Sample Groovy / Java File Chooser

Here is a quick bit f code to choose a single file or directory. It’s written in groovy but uses java’s JFileChooser. It has many more options than demonstrated here, Look at the oracle link here.

// groovy sample to choose one file using java's  JFileChooser
// would only allow choice of a single directory by setting another JFileChooser feature
// http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html
// see more examples in above link to include a file filter
import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
// start to choose files from pwd
def initialPath = System.getProperty("user.dir");
JFileChooser fc = new JFileChooser(initialPath);
// fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result = fc.showOpenDialog( null );
switch ( result )
{
   case JFileChooser.APPROVE_OPTION:
      File file = fc.getSelectedFile();

      def path =  fc.getCurrentDirectory().getAbsolutePath();
      println "path="+path+"\nfile name="+file.toString();
      break;
   case JFileChooser.CANCEL_OPTION:
   case JFileChooser.ERROR_OPTION:
      break;
}

Sample Java / Groovy Code to Play MP3 Sound Clip

Groovy

The groovy programming language is a super version of the java language specification. If you are a java developer, you can either rework this code sample or google elsewhere for an exact java example.

Steps To Test

Here is a sample program originally written in java. Here i’ve used groovy as a convenience. This code requires an mp3 codec which is found in the JLayer project seen here: 1.0.1 so download that jar. The latest version appears to be JLayer 1.0.1 from Nov.2008. This is what i used in this test.

  1. Make a new directory
  2. copy above jar into that directory
  3. place a sound or music clip recorded in the mp3 format into that directory
  4. copy the following groovy source code into that directory
  5. be sure you have a working groovy install from here
  6. open terminal command session
  7. change into that directory
  8. compile source code: groovyc -classpath .:jl1.0.1.jar SampleMP3player.groovy
  9. download my two sample mp3 files at bottom of post and place in same directory. One of these is teardrops.mp3
  10. test code : groovy -classpath .:jl1.0.1.jar SampleMP3player.groovy teardrops.mp3 35

ok, that test plays the mp3 file named teardrops.mp for 35 seconds. The second parameter is optionally an integer number of seconds of duration to play the sound clip (default is 10 sec.s). If your clip is longer, the remainder will not be heard as the .close() method stops the playback after timer expiry. If the sound clip is less than that, task blocks until timer expires even if sound clip finishes playing earlier.

Groovy Source Code

Code Comments

Place the following lines at the top of your source code file named SampleMP3player.groovy

/*************************************************************************
 *  Compilation:  groovyc -classpath .:jl1.0.1.jar SampleMP3player.groovy         (OS X)
 *                groovyc -classpath .;jl1.0.1.jar SampleMP3player.groovy         (Windows)
 *  Execution:    groovy -classpath .:jl1.0.1.jar SampleMP3player filename.mp3  (OS X / Linux)
 *                groovy -classpath .;jl1.0.1.jar SampleMP3player filename.mp3  (Windows)
 *
 *  Plays an MP3 file using the JLayer MP3 library.
 *
 *  Reference:  http://www.javazoom.net/javalayer/sources.html for jlayer jar with mp3 converter
 *
 *  To execute, you will need jl1.0.1.jar from the website above in your working directory with compiled source
 *  along with some .mp3 files in the same dir.
 ************************************************************************
*/
// /Volumes/PENDRIVE/MP3Player $ groovyc -classpath .:jl1.0.1.jar SampleMP3player.groovy
// /Volumes/PENDRIVE/MP3Player $ groovy -classpath .:jl1.0.1.jar SampleMP3player.groovy track6.mp3
// *
// *  redapple:jim /Volumes/PENDRIVE/MP3Player $ groovy -classpath .:jl1.0.1.jar SampleMP3player.groovy teardrops.mp3 35

Code Body

Place the following lines in the same source code file as above and following those comments


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import javazoom.jl.player.Player;

public class SampleMP3player
{
// name of sound to be played – should be an MP3 format
String filename;
Player player;
def timer = new Timer()
int seconds = 10;

// constructor needs name of an MP3 file
public SampleMP3player(fn) {
this.filename = fn;
if (!new File(this.filename).exists() || (!this.filename.toLowerCase().endsWith(“.mp3”)) )
{
println “fatal: need mp3 file name as parameter\nNot found -> sound clip:”+this.filename
help();
} // end of if

} // end of constructor

// constructor needs name of an MP3 file
public SampleMP3player(fn,secs) {
//this.filename = fn;
this(fn);
this.seconds = secs as Integer;
} // end of constructor

/* sample code to try running another process while sound clip plays
// declare a task that runs after 10 seconds
def task = timer.runAfter(10000)
{
println “Actually executed at ${new Date()} for file ${filename}.”

// so while this task has started, wait another 10+ seconds before closing player
// which stops the music & issue an exit to finish the thread & JVM
sleep(new Random().nextInt(10) * 1000);
this.close();
System.exit(0);
}
— */

public void close()
{
if (player != null) player.close();
} // end of close()

// stream an MP3 file to audio output
public void play()
{
try
{
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
}
catch (Exception e)
{
println(“Problem playing file ” + filename);
println e
} // end of try/catch

// use new thread to play in background
new Thread(){
public void run()
{
try { player.play(); }
catch (Exception x) { println x; }
} // end of run()

}.start(); // yes, we gotta start playing the clip in a new thread

} // end of play()

def static help()
{
println “groovy -classpath .:jl1.0.1.jar SampleMP3player \nfatal: need mp3 file name as parameter”
println “=== end ===”;
System.exit(1);
}

// typical main method
public static void main(String[] args)
{
println “=== start ===”;
String soundfilename = null;

if (args.size() 1)
{
mp3 = new SampleMP3player(soundfilename, args[1]);
} // end of if
else
{
mp3 = new SampleMP3player(soundfilename);
} // end of else

mp3.play();

// small example to run a task after some seconds that will close & stop the currently playing sound clip
// for testing, uncomment the next line plus def task method above
// println “Current date is ${new Date()}. Task is executed at ${new Date(mp3.task.scheduledExecutionTime())}.”

// note that we need to do process or task that will take up time as the sound clip stops playing when the .close() method is invoked
sleep(mp3.seconds * 1000);

// when done, stop playing it
println “ready to close() after ${mp3.seconds} seconds”;
mp3.close();

// play from the beginning
//def playthis = “teardrops.mp3”
//mp3 = new SampleMP3player(playthis);
//mp3.play();
System.exit(0);

println “=== end ===”;

} // end of main

} // end of class

enjoy 🙂

Sound Samples

Note that i had to do a funny as wordpress does not allow me to insert .mp3 files into my post so i rename them with a .jpg image suffix. This ensures all the bits reach your directory intact. But you will need to rename the ‘image’ to be able to use these clips.

Click here to download track6-mp3.jpg into your target folder then please rename it as track6.mp3 or look here: https://github.com/jnorthr/track6/tree/master/war/resources

Click here to download the teardrops3.mp3 sound clip into your target folder then please rename it as teardrops.mp3

Directory Layout

My directory looked like this after the above testing was complete.

Folder Content for MP3 Test
Folder Content for MP3 Test

Sample Java Code to Play Sound Effect

NOTE: If your sound clip is MP3, better to read my post for those here.

Intro

Must be brief. Had a need for a bit of java code to play a sound in one of my guis. Found ‘sound recorder’ program under accessories in window 7 on my wife’s system. Had identified a sound bite i could play. How to get it to play on an apple using java code ?

Audio Formats Are A Bother

It seems the format your audio sound clip is stored in, does influence whether you can use java to play it. The oracle javax.sound.sampled.*; package has decoders for sound clips stored in several formats. This sample java code uses javax.sound.sampled.AudioFileFormat.Type choices so only  .WAVE .AU .AIFF .AIFC .SND audio formats are supported – NOT mp3 (see link below for .MP3 sample code so you will need to brew your own if thats what you need, or else convert your sound file into one of the above formats or see my MP3 post here.)

STEPS

1. ran sound recorder with attached webcam microphone to capture the sound from window/7 speakers. This sound was saved in the only choice available for that tool which was the windows audio format .wma and hopefully you wont need to do this agro if you can get your sound clip into a usable format.

2. copied snick1.wma to usb key and mounted on my apple macbook ( actually did a dozen files to confirm it all works, so names range from snick1 thru snick7 )

3. found this tool from an australian group to convert the .wma sound file into another format. see: http://www.nch.com.au/switch/index.html?gclid=CKbEtY6Ex7QCFW3KtAod-TYAlQ

4. downloaded that conversion tool and ran it on my apple mac against my sound file that i named as snick1.wma on windows giving me snick1.wav output. Had to do this as .wav is one of the few audio formats supported by the java package.

5. found references to build java source code :

6. built java class file from code seen here saved as SoundEffect.java

import javax.sound.sampled.*;
import java.net.*;
public class SoundEffect
{
 URL url;
 AudioInputStream ais;
 Clip clip;
 // simple audio file name like snick7.wav works if in same folder as this.class
 // but full filenames like /Volumes/PENDRIVE/groovy/snick7.wav don't 
 public SoundEffect(String fn)
 {
   try
   {
     url = SoundEffect.class.getResource(fn);
     ais = AudioSystem.getAudioInputStream(url);
     clip = AudioSystem.getClip();
     clip.open(ais);
    clip.start(); 
   } 
   catch(Exception e){e.printStackTrace();}
 } // end of constructor

 // one command line argument must be simple audio file name in one of the formats noted above (mp3 NOT supported)
 public static void main(String args[]) throws Exception
 {
 SoundEffect se = new SoundEffect(args[0]);
 }
}

Code Notes

javac SoundEffect.java
java SoundEffect snick7.wav

Will only play  .WAVE .AU .AIFF .AIFC .SND audio formatted audio files in the same directory as this class. Supported file formats can be either 8-bit or 16-bit, with sampling rate from 8 kHz to 48 kHz.

Warning

This sample code is NOT a threaded example so it will tie up your gui thread while it runs; depending on the length of your .wav file, this could be a LONG time !

Wanted to also give you a sample .wav file to play with after you compile this code but wordpress does not allow me to post this sound clip in the .wav format, so i’ve done a funny to add the .jpg to snick7 name so after you download it and put it in the same directory as your compiled class file, you’ll need to rename this sound clip as snick7.wav and when testing this idea, my browser would not let me change the filename suffix on a SAVE AS menu option, so saved with name browser suggested into my target folder, then used a file rename command. If this works and you can play this sound clip, you should hear a really short ‘kachink’ sound  – good luck 🙂

whether you can download this sample .wav file depends on your browser, but try: https://github.com/jnorthr/track6/tree/master/war/resources/snick7.wav

snick7.wav.jpg must be renamed as snick7.wav after you download it.
snick7.wav

Java Open JDK 7 / SDK 1.7 for Apple PPC iMac / Macbook G3, G4 and G5 – Part 2

Review

Please read part one for links to references that helped with this installation. After completing these steps, my aging Apple iMac PPC system had a fully functional openJDK 1.7 and now google app engine is happy and no longer gives me a bad version in class file message. Ok, the down-side of this way of doing it is that the apple-specific features that make java gui’s look-like-an-apple are not there. I can live with that as i do not do much java gui desktop hacking anyway. If you do, you may need to re-think this approach.

Essential Steps

  1. Downloaded OpenJDK, Java 1.7 from https://wikis.oracle.com/display/OpenJDK/Darwin9Build
  2. Changed permissions
  3. Copied / moved new package to temporary location to uncompress and unpack the content : /usr/java7
  4. Fixed up permissions and ownership of the components
  5. Confirmed setup would work in it’s temporary home and was in fact jdk 1.7
  6. Created a final folder the the standard apple folder to place the 1.7 assets and where it all would reside. Just to keep things tidy, chose to put this into the apple folder (see below) at /System/Library/Frameworks/JavaVM.framework/Versions/ so it sits in the apple folder used for the apple versions of java.
  7. Moved everything from /usr/java7 to /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0 folder
  8. Used the temporary /usr/java7 folder as the landing place for all the new soft logical links pointing to my new jdk 1.7
  9. Changed all the PATH setup files to have /usr/java7 before the apple supplied same in /usr/bin where all the soft links to apple’s java versions sit, think this was the ~/.profile and .bashrc and some others i forgot to write down (google around to find out which ones you need on your system)
  10. Log out or reboot
  11. From terminal command line tried java -version and javac -version to confirm success, Houston we have lift-off !! JDK 1.7 is ready !!! Therefore since, /usr/java7 links are available before the typical apple links to java in /usr/bin folder, it all seems to hang together. Hope yours does too.
  12. Retry google app engine 1.7.0 and voila !

—-

Took kurt miller’s macppc build choice of jdk 7 to download from https://wikis.oracle.com/display/OpenJDK/Darwin9Build after download was complete, went into my download folder:

Changed directories to the download folder and changed the permissions of the downloaded jdk payload, just to avoid authority/permissions issues
sudo chmod 777 openjdk7u2-macppc-fcs-2012-03-14.tar.bz2

Moved the jdk to my /usr/local folder as a temporary landing place
sudo mv openjdk7u2-macppc-fcs-2012-03-14.tar.bz2 /usr/local/

Went into that folder
cd /usr/local/

Uncompressed the jdk payload to get to the .tar
sudo bzip2 -d openjdk7u2-macppc-fcs-2012-03-14.tar.bz2

Unpacked the tape archive using tar command

sudo tar -xvf openjdk7u2-macppc-fcs-2012-03-14.tar
cd /usr/local/openjdk7u2-macppc-fcs-2012-03-14
ls -al

Is it here  before unpack ? Yes.
// ————————–
iMac:java7 jim$ cd /usr/local/
iMac:local jim$ ls -al
total 286464
drwxr-xr-x   5 root  wheel        170 27 Jul 17:01 .
drwxr-xr-x@ 13 root  wheel        442 27 Jul 23:41 ..
drwxr-xr-x  14 jim   admin        476 26 Jul 23:55 bin
drwxr-xr-x   8 root  wheel        272 23 Dec  2009 git
-rwxrwxrwx   1 root  staff  146667520 27 Jul 01:08 openjdk7u2-macppc-fcs-2012-03-14.tar
// ————————–

Went into that folder
cd openjdk7u2-macppc-fcs-2012-03-14

Went into the folder holding the payload executables
cd bin/

Let’s see if 1) they will execute or not 2) what jdk/sdk version are they ?
./java -version
./javac -version

should say jdk 1.7-ish !!!

Went back to user home folder
cd ~

What’s here ?
ls -al

If we have fixed the paths in the .profile (see below for edit ideas), then these commands are part of the soft links to our new java :
java
java -version

Er, no, not yet.

Made a new jdk 7 folder in the typical apple location
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo mkdir 1.7.0
cd 1.7.0

cd /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0

// here’s a look at my folder setup after the above steps. Note the new 1.7.0 folder created to host the openJDK assets
// —————————————————————–
iMac:~ jim$ cd /System/Library/Frameworks/JavaVM.framework/Versions/
iMac:Versions jim$ ls -al
total 48
drwxr-xr-x  13 root  wheel  442 27 Jul 12:04 .
drwxr-xr-x  12 root  wheel  408  3 Aug  2011 ..
lrwxr-xr-x   1 root  wheel    5  3 Aug  2011 1.3 -> 1.3.1
drwxr-xr-x   3 root  wheel  102 29 Sep  2007 1.3.1
lrwxr-xr-x   1 root  wheel    5 18 Sep  2009 1.4 -> 1.4.2
lrwxr-xr-x   1 root  wheel    3 22 Dec  2007 1.4.1 -> 1.4
drwxr-xr-x   8 root  wheel  272 22 Dec  2007 1.4.2
lrwxr-xr-x   1 root  wheel    5  3 Aug  2011 1.5 -> 1.5.0
drwxr-xr-x   8 root  wheel  272 22 Dec  2007 1.5.0
drwxr-xr-x  14 root  wheel  476 27 Jul 12:06 1.7.0  <—- new folder as permanent home for jdk 1.7
drwxr-xr-x   9 root  wheel  306 27 Jul 17:08 A
lrwxr-xr-x   1 root  wheel    1 27 Jul 00:44 Current -> A
lrwxr-xr-x   1 root  wheel    5 10 May 17:11 CurrentJDK -> 1.5.0
// —————————————————————

Moved all the bits from jdk7 in /usr/local to here
sudo mv /usr/local/openjdk7u2-macppc-fcs-2012-03-14/* .

Changed owners on all asets
sudo chown -R root:wheel .

// ——————————————–
Went home
cd ~

Ready to fix some path declarations to point to the new /usr/java7 folder full of links plus something for my google app engine install – you won’t need to do APP_ENGINE_HOME if you do not use google app engine. Just place /usr/java7 before the /usr/bin folder in your path identified by $PATH in our export statement below
sudo nano .profile

// ——————————-
export DERBY_HOME=/Volumes/Media/Software/derby/db-derby-10.5.3.0
export GROOVY_HOME=/Volumes/Media/Software/groovy-1.9.0
export PLAY_HOME=/Volumes/Media/Software/Play-1.2.4
export APP_ENGINE_HOME=/Volumes/Media/Software/appengine-java-sdk-1.7.0
export PATH=”.:$PLAY_HOME:$DERBY/bin:$GROOVY_HOME/bin:/usr/java7:$PATH”

then ctrl+o +enter key to save
then ctrl-x  to exist
// ———————————–

Make your export PATH declaration look similar to the above.

// —————————-
also may need to fix up / review paths in :
sudo nano .bash_profile
sudo nano .bashrc

// —  when successful, my new PATH variable looks like this:
iMac:Versions jim$ cd ~
iMac:~ jim$ cat .profile
export DERBY_HOME=/Volumes/Media/Software/derby/db-derby-10.5.3.0
export GROOVY_HOME=/Volumes/Media/Software/groovy-1.9.0
export PLAY_HOME=/Volumes/Media/Software/Play-1.2.4
export APP_ENGINE_HOME=/Volumes/Media/Software/appengine-java-sdk-1.7.0
export PATH=”.:$PLAY_HOME:$DERBY/bin:$GROOVY_HOME/bin:/usr/java7:$PATH”
export PS1=”\u@\h\w: “

iMac:~ jim$ echo $PATH
.:/Volumes/Media/Software/Play-1.2.4:/bin:/Volumes/Media/Software/groovy-1.9.0/bin:/Volumes/Media/Software/appengine-java-sdk-1.7.0/bin:/usr/java7:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin

// ————————————————————–
So notice how /usr/java7 links to java are in the path ahead of/before /usr/bin ?
This way, the new pointers and links to the openJDK7 assets are found first when OSX does a path search for executables

My /usr/bin looks like this and has apple declared soft links to their version of java :
iMac:bin jim$ pwd
/usr/bin

// —————————————————————
iMac:bin jim$ ls -al j*
lrwxr-xr-x   1 root  wheel     73 10 May 16:55 jar -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jar
lrwxr-xr-x   1 root  wheel     79 10 May 16:55 jarsigner -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jarsigner
lrwxr-xr-x   1 root  wheel     74 10 May 16:55 java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
lrwxr-xr-x   1 root  wheel     75 10 May 16:55 javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac
-r-xr-xr-x   1 root  wheel  50976 24 Sep  2007 javaconfig
lrwxr-xr-x   1 root  wheel     77 10 May 16:55 javadoc -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javadoc
lrwxr-xr-x   1 root  wheel     75 10 May 16:55 javah -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javah
lrwxr-xr-x   1 root  wheel     75 10 May 16:55 javap -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javap
-r-xr-xr-x   1 root  wheel  72336 24 Sep  2007 javatool
lrwxr-xr-x   1 root  wheel     76 10 May 16:55 javaws -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javaws
lrwxr-xr-x   1 root  wheel     78 10 May 16:55 jconsole -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jconsole
lrwxr-xr-x   1 root  wheel     73 10 May 16:55 jdb -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jdb
lrwxr-xr-x   1 root  wheel     74 10 May 16:55 jhat -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jhat
lrwxr-xr-x   1 root  wheel     75 10 May 16:55 jinfo -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jinfo
lrwxr-xr-x   1 root  wheel     74 10 May 16:55 jmap -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jmap
lrwxr-xr-x   1 root  wheel     73 10 May 16:55 jps -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jps
lrwxr-xr-x   1 root  wheel     79 10 May 16:55 jsadebugd -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jsadebugd
lrwxr-xr-x   1 root  wheel     76 10 May 16:55 jstack -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jstack
lrwxr-xr-x   1 root  wheel     75 10 May 16:55 jstat -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jstat
lrwxr-xr-x   1 root  wheel     76 10 May 16:55 jstatd -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jstatd
lrwxr-xr-x   1 root  wheel     72 10 May 16:55 jvisualvm -> /System/Library/Java/Support/VisualVM.bundle/Contents/Home/bin/jvisualvm
// ————————————————————-

Ok, then made another folder for all the new soft links to the new java – the one we declared in the changes above…
mkdir /usr/java7
cd /usr/java7

// created all these soft links essentially duplicating all those found in normal apple folders
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/java java
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javac javac
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javadoc javadoc
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javah javah
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javap javap
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javaws javaws
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jconsole jconsole
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jdb jdb
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jhat jhat
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jinfo jinfo
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jmap jmap
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jps jps
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jstack jstack
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jstat jstat
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jstatd jstatd
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/keytool keytool
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jar jar
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jarsigner jarsigner
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/extcheck extcheck
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/apt apt
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/appletviewer appletviewer
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/idlj idlj
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/orbd orbd
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/pack200 pack200
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/policytool policytool
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/unpack200 unpack200
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/tnameserv tnameserv
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/serialver serialver
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/servertool servertool
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/rmiregistry rmiregistry
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/rmic rmic
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/rmid rmid

Fixed up permission
sudo chmod 777 *

Went home to see if path changes took – no!
Had to open a new terminal session to use new changes so that fresh path layout was seen in new terminal session.
Rebooted system just to be sure.

After reboot, brought up a terminal window and went home

cd ~

// ————–>
Tried these commands to confirm successful placement of java 7 above/before the apple version of java found in /usr/bin which pointed to jdk 1.5 on my system (and still does). we have not disabled the apple versions, but apple OSX does not really know that JDK 1.7 is in place.

iMac:java7 jim$ javac -version
javac 1.7.0-internal

iMac:java7 jim$ java -version
openjdk version “1.7.0-internal”
OpenJDK Runtime Environment (build 1.7.0-internal-truk_2012_03_14_11_04-b00)
OpenJDK Zero VM (build 22.0-b10, interpreted mode)

Now tried the google app engine app_devserver.sh command again and voila, we have a happy google app engine we can use for development with openJDK 7

Thanx to Kurt Miller for his heroic efforts to put it all together for us old iMac users !!!

Java Open JDK 7 / SDK 1.7 for Apple PPC iMac / Macbook G3, G4 and G5 – Part 1

Part Two Is Here

Intro

Needed to run latest google app engine development tools on my aging Apple iMac with PPC processor and Mac OSX 10.5.8 – the latest/last incarnation for PPC systems.This was to overcome a bad version in .class file message in the google implemention.

This limited my non-intel Power P/C chipset system to JDK 1.6 as a max working java SDK, and even then it was problematic. So needed to see if it was possible to install the newer JDK 1.7. Since java is so tightly woven into the fabric of OSX, after a lot of research, it became obvious there was no way to do this the ‘apple way’. So i decided to try the open java 7 build as a virgin installation, thus avoiding any reference to the apple versions of java.

Turned out, this is a long-winded topic needing more than a single post. So will describe this ordeal in more than one post. In this post, i’ve listed the reference links used to research this topic. Turns out this is not as super complex as i first thought but for the mo. please review these links :

Reference Links

https://wikis.oracle.com/display/OpenJDK/Darwin9Build for ppc build links

Index of /OpenJDK/macppc and download link: http://www.intricatesoftware.com/OpenJDK/macppc/

openjdk-osx-build – OpenJDK 7 and 8 Community packages for OS/X Snow, Lion and Mountain Lion – Google Project Hosting: http://code.google.com/p/openjdk-osx-build/
Java Evangelist John Yeary’s Blog: OpenJDK 7 on Apple G5 PowerPC on Mac OS X 10.5.8: http://javaevangelist.blogspot.fr/2012/02/openjdk-7-on-apple-g5-powerpc-on-mac-os.html

OpenJDK: Mac OS X Port Project :http://openjdk.java.net/projects/macosx-port/

Issue 4712 – googleappengine – Java for Mac OS X Update Breaks dev_appserver – Google App Engine – Google Project Hosting: http://code.google.com/p/googleappengine/issues/detail?id=4712

google dev_appserver bad version number in .class apple ppc – Google Search:https://www.google.fr/search?q=google+dev_appserver+bad+version+number+in+.class+apple+ppc&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:unofficial&client=firefox-a

Installing Java 7 on Mac OS X | Javalobby : http://java.dzone.com/articles/installing-java-7-mac-os-x

Java – How install a specific jdk on Mac OS X? – Stack Overflow : http://stackoverflow.com/questions/1577014/how-install-a-specific-jdk-on-mac-os-x

openjdk-osx-build – OpenJDK 7 and 8 Community packages for OS/X Snow, Lion and Mountain Lion – Google Project Hosting : http://code.google.com/p/openjdk-osx-build/

New Soft Link Layout – Post Install

This is not the correct place to show you this set of logical soft links, but just stuck it here for the moment. It shows my new /usr/java7 folder holding just the fresh links to the newly installed java7 bits.

// ====================================================================
 iMac:usr jim$ cd /usr/java7
 iMac:java7 jim$ ls -al
 total 256
 drwxrwxrwx  34 root  wheel  1156 27 Jul 23:51 .
 drwxr-xr-x@ 13 root  wheel   442 27 Jul 23:41 ..
 lrwxr-xr-x   1 root  wheel    75 27 Jul 23:48 appletviewer -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/appletviewer
 lrwxr-xr-x   1 root  wheel    66 27 Jul 23:48 apt -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/apt
 lrwxr-xr-x   1 root  wheel    71 27 Jul 23:48 extcheck -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/extcheck
 lrwxr-xr-x   1 root  wheel    67 27 Jul 23:49 idlj -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/idlj
 lrwxr-xr-x   1 root  wheel    66 27 Jul 23:47 jar -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jar
 lrwxr-xr-x   1 root  wheel    72 27 Jul 23:47 jarsigner -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jarsigner
 lrwxr-xr-x   1 root  wheel    67 27 Jul 23:44 java -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/java
 lrwxr-xr-x   1 root  wheel    68 27 Jul 23:44 javac -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javac
 lrwxr-xr-x   1 root  wheel    70 27 Jul 23:44 javadoc -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javadoc
 lrwxr-xr-x   1 root  wheel    68 27 Jul 23:44 javah -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javah
 lrwxr-xr-x   1 root  wheel    68 27 Jul 23:44 javap -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javap
 lrwxr-xr-x   1 root  wheel    69 27 Jul 23:44 javaws -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/javaws
 lrwxr-xr-x   1 root  wheel    71 27 Jul 23:45 jconsole -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jconsole
 lrwxr-xr-x   1 root  wheel    66 27 Jul 23:46 jdb -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jdb
 lrwxr-xr-x   1 root  wheel    67 27 Jul 23:46 jhat -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jhat
 lrwxr-xr-x   1 root  wheel    68 27 Jul 23:46 jinfo -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jinfo
 lrwxr-xr-x   1 root  wheel    67 27 Jul 23:46 jmap -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jmap
 lrwxr-xr-x   1 root  wheel    66 27 Jul 23:46 jps -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jps
 lrwxr-xr-x   1 root  wheel    69 27 Jul 23:47 jstack -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jstack
 lrwxr-xr-x   1 root  wheel    68 27 Jul 23:47 jstat -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jstat
 lrwxr-xr-x   1 root  wheel    69 27 Jul 23:47 jstatd -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/jstatd
 lrwxr-xr-x   1 root  wheel    70 27 Jul 23:47 keytool -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/keytool
 lrwxr-xr-x   1 root  wheel    67 27 Jul 23:49 orbd -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/orbd
 lrwxr-xr-x   1 root  wheel    70 27 Jul 23:49 pack200 -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/pack200
 lrwxr-xr-x   1 root  wheel    73 27 Jul 23:49 policytool -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/policytool
 lrwxr-xr-x   1 root  wheel    67 27 Jul 23:51 rmic -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/rmic
 lrwxr-xr-x   1 root  wheel    67 27 Jul 23:51 rmid -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/rmid
 lrwxr-xr-x   1 root  wheel    74 27 Jul 23:51 rmiregistry -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/rmiregistry
 lrwxr-xr-x   1 root  wheel    72 27 Jul 23:50 serialver -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/serialver
 lrwxr-xr-x   1 root  wheel    73 27 Jul 23:50 servertool -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/servertool
 lrwxr-xr-x   1 root  wheel    72 27 Jul 23:50 tnameserv -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/tnameserv
 lrwxr-xr-x   1 root  wheel    72 27 Jul 23:50 unpack200 -> /System/Library/Frameworks/JavaVM.framework/Versions/1.7.0/bin/unpack200
iMac:java7 jim$ javac -version
 javac 1.7.0-internal
iMac:java7 jim$ javah
 Usage:
   javah [options] <classes>
 where [options] include:
   -o <file>                Output file (only one of -d or -o may be used)
   -d <dir>                 Output directory
   -v  -verbose             Enable verbose output
   -h  --help  -?           Print this message
   -version                 Print version information
   -jni                     Generate JNI-style header file (default)
   -force                   Always write output files
   -classpath <path>        Path from which to load classes
   -bootclasspath <path>    Path from which to load bootstrap classes
 <classes> are specified with their fully qualified names
 (for example, java.lang.Object).
iMac:java7 jim$ javah -version
 javah version "1.7.0-internal"
iMac:java7 jim$ pwd
 /usr/java7
 // started out to fix ownership and permissions of jdk folders and components
 // but this became a long affair, so will detail this in the next post
 // =========================================================
 iMac:usr jim$ sudo chmod 777 java7

Part Two Is Here