Category: Java

WebEx in Fedora 15 (64 bit)

At one point, I thought WebEx was working natively in 64-bit Linux.  Either I am mistaken or it no longer works on 64-bit.  So, I decided to dust off my old 32-bit hack where you install 32-bit versions of Java and Firefox to make it all work.

Earlier, I had thought I would use my regular 64-bit installation, and I had posted my hooking Java up to Firefox for WebEx.  I was rightly corrected on troshlyak’s blog.  The 64-bit will work, but you can’t share your desktop or view another’s desktop.  So, I am back to the old way.  So, here’s what I did…

I downloaded the two programs:

I created a directory in ~/bin/webex to hold it all.  Under that, I put the Java SDK under the “jdk1.7.0_01” directory.  Then, I put Firefox under “firefox”.

Environment Script:

I created this script in ~/bin/webex/env.sh:

#!/bin/sh

export WEBEX_HOME=~/bin/webex
export JDK_HOME=$WEBEX_HOME/jdk1.7.0_01
export JAVA_HOME=$JDK_HOME/jre
export FIREFOX_HOME=$WEBEX_HOME/firefox
export MOZ_PLUGIN_PATH=$FIREFOX_HOME/plugins
export PATH=$FIREFOX_HOME:$JAVA_HOME/bin/:$JDK_HOME/bin/:$PATH

To make sure you have it right, you can check it like this:

[skp@pecan bin]$ . ~/bin/webex/env.sh
[skp@pecan bin]$ which java
~/bin/webex/jdk1.7.0_01/jre/bin/java
[skp@pecan bin]$ java -version
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Server VM (build 21.1-b02, mixed mode)

Now, you can link in the Java plugin like this:

mkdir $MOZ_PLUGIN_PATH
ln -s $JAVA_HOME/lib/i386/libnpjp2.so $MOZ_PLUGIN_PATH/libnpjp2.so

Now, fire up firefox.  Note you may be asked to create the WebEx profile.  Make sure you create a profile with the same name you use on the command line so it won’t ask you again.

firefox --no-remote -P WebEx http://java.com/en/download/testjava.jsp

This should give you a successful Java applet working on the test page.  You also should see the architecture as i386.

Java Test Successful and shows i386

Finally, I created a ~/bin/webex.sh script to launch webex easily for me.

#!/bin/bash

cd ~/bin/webex
. ./env.sh
firefox --no-remote -P WebEx

And you should be good to go.

Java: getSystemJavaCompiler returns null!

After reinstalling my laptop with Ubuntu Natty, I had an issue with one of my custom built tools.  I have this tool that installs a Tomcat-based web application and server.  In the part that compiles the JSON library, I received a NullPointerException.

On further examination, I found that ToolProvider.getSystemJavaCompiler() was returning null for some reason.  I found the answer on IBM DeveloperWorks:

The ToolProvider.getSystemJavaCompiler()method can return null if tools.jar is not in the application’s classpath. The CharStringCompilerclass detects this possible configuration problem and throws an exception with a recommendation for fixing the problem. Note that Sun’s licensing allows tools.jar to be redistributed with the JRE.

What I found was that I was using a JRE instead of a JDK installation.  Of course, when I switch the Java Home to my JDK, I had some other error and the App wouldn’t even run.  So, I added the tools.jar from the JDK installation to the classpath and ran it with the JRE, and everything worked fine.

So, here is the code I use to compile (including the catch for the missing tools.jar):

		//compile
		JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
		// handle issue where tools.jar is not on the classpath
		if(jc == null) {
			log.logException(new InstallException("Could not access the system Java compiler -- check to make sure tools.jar is on the class path."));
			return;
		}
		StandardJavaFileManager fm = jc.getStandardFileManager(null, null, null);
		File compilePath = new File(unzipPath, "org/json");
		Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(compilePath.listFiles());
		for(JavaFileObject f : files) {
			log.logInformation("Compiling - " + f.getName());
		}
		CompilationTask task = jc.getTask(log.getStream(), fm, null, null, null, files);
		try {
			fm.close();
		} catch (IOException e) {
			log.logException(new InstallException("Could not unzip " + zipPath, e));
		}
		boolean result = task.call();
		log.logInformation("**Compile result = " + result);

Resources

IBM DeveloperWorks: Create dynamic applications with javax.tools

Installing Sun Java 6

I was able to install the package sun-java6-jdk from synaptic with no problems.  The update alternatives were what caused me problems:

skp@pecan:~$ sudo update-java-alternatives --list
[sudo] password for skp:
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun
skp@pecan:~$ sudo update-java-alternatives --set java-6-sun
update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-alternatives: error: no alternatives for xulrunner-1.9-javaplugin.so.
update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-alternatives: error: no alternatives for xulrunner-1.9-javaplugin.so.
skp@pecan:~$

These errors threw me off at first because I thought they kept it from working.  You can run java -version to see that it really is using the correct version.  Sun’s version reports this:

skp@pecan:~$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
skp@pecan:~$

Open JDK reports this:

skp@pecan:~$ java -version
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.1) (6b22-1.10.1-0ubuntu1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

As far as I can tell, the “No Alternatives for” messages aren’t causing a problem, so I am not going to worry about it.  If you have any info on that, please comment.

This is the error message that I am getting from my Java that the Sun JDK has solved in the past. I’ll leave it for another later post, but I wanted to share it in case anyone has any ideas. Please comment if you do:

The program '.' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
  (Details: serial 1359 error_code 8 request_code 140 minor_code 4)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

Resources

Upgrading Eclipse to 3.6

I just realized while trying to install Visual Editor, that Eclipse has a new version.  I am using 3.5, but 3.6 is available.

I could just download eclipse from their website, but that would be too easy!  I guess I was hoping that if I use the repository, the packaging team would keep it up to date.

I found this thread discussing upgrading.  They say it doesn’t work, but I thought I would give it a try myself.  Worst cast, I could download it manually like #11 describes.

So, I went to Synaptic and opened the Settings > Repositories.  Then, I added the repository:

deb https://launchpad.net/~eclipse-team/+archive/debian-package lucid main

When I clicked Reload on Synaptic, I got this error message:

Failed to fetch https://launchpad.net/~eclipse-team/+archive/debian-package/dists/lucid/main/binary-amd64/Packages.gz  The requested URL returned error: 404
Some index files failed to download, they have been ignored, or old ones used instead.
Failed to fetch https://launchpad.net/~eclipse-team/+archive/debian-package/dists/lucid/main/binary-amd64/Packages.gz  The requested URL returned error: 404Some index files failed to download, they have been ignored, or old ones used instead.

I wonder if it is because I am running the 64bit version of Ubuntu.

Anyway, since it didn’t work, I downloaded eclipse from the Eclipse website.  Then, I extracted the tar ball into my Downloads directory.  From the command line, I changed directory into the newly created eclipse directory.  Then, I ran this command to copy it to /usr/lib —

sudo cp -r * /usr/lib/eclipse/

One thing to keep in mind is that you probably want to write down what extensions you have installed and the sites so that you can reinstall them.

Resources

Ubuntu Forums: Update Eclipse 3.5 to 3.6

Bring the Web Interface to Swing

I have been fighting with using Swing to create user interfaces for while now.  The advantage with Swing is that it comes with Java and you don’t have to install any additional tools or jars to work with it.  The disadvantage is that you have to code everything manually.  I haven’t found a easy interface for designing GUI’s with Swing.

Since I have done a lot of work with HTML and web development, I thought it might be worth looking at building an HTML front end enveloped by Swing windows.  The only problem is that to make the interface work, I need Javascript.

The LOBO Project looks like my best bet here from my searches so far.  I found it from this Stack Overflow Thread.  It is a pure Java browser.  So, I am thinking that I can embed it in my projects and make that the front-end.

The same thread mentioned using something contained in JDIC.  I think I have used that for notification icons already, so that might be something worth looking into.  I found two other projects: Swingx-WS and WebSwing, but both of those don’t look as promising.

Then, I found Kyle Cordes’ post on using Rhino with Swing.  His code is available, so I need to check it out: Git Hub.

To step back a little, what I really want is a better alternative for creating GUIs.  I found a cool article, that had some other options.  I thought it was interesting that they mentioned having HTML as the front end.  The Visual Editor in Eclipse sounded like something else to check out.  I am going to have explore these instructions for installing more and this tutorial for including custom components.  Other open source options are FormLayoutMaker, Java Object Face, and the Atris Framework.

Another option that is worth looking into is a Chrome Web App.  I found a nice little guide for creating one, or you can read Google’s documentation.  My issue with that is that I need additional access that I don’t think Chrome will give me.

Please comment if you have any ideas.

Tip: Uploading to Google Code

I learned this the hard way: put a version number in your Google Code releases!

I kept receiving an error when I tried to upload my new Jar file.  It was the same 403 error as this person.  The problem is that you can’t overwrite files any more.  Each new download needs to have it’s own unique file name.

So, the easy fix is to include and incrementing version number in the file name.

From Ant, I was able to accomplish the version number is this manner:

  • I created a version.txt to hold a minor number and major number property — saves the version
  • In the destfile parameter of the Jar step, I use the ${major.number} and ${minor.number} properties in the file name.
  • In the release section, I use the propertyfile command to increment the version number

Here is the full Ant Build file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><project default="all" name="Create Runnable Jar for Project ProjectShaphan">    <target name="all" depends="clean,compile,create_run_jar"/>
<target name="clean">       <delete dir="bin"/>    </target>
<target name="compile">       <mkdir dir="bin"/>       <javac destdir="bin">          <src path="src"/>          <classpath>             <pathelement path="/home/skp/app/workspaces/pscompare/ProjectJob/demo-bin"/>          	<fileset dir="lib">          		<include name="**/*.jar"/>          	</fileset>          </classpath>       </javac>    </target>
<target name="create_run_jar">    <!--this part was created by Eclipse Runnable JAR Export Wizard-->    <!--ANT 1.7 is required                                        -->        <property file="./version.txt"/>        <jar destfile="project-shaphan-${major.number}.${minor.number}.jar" filesetmanifest="mergewithoutmain">            <manifest>                <attribute name="Built-By" value="${user.name}"/>                <attribute name="Main-Class" value="com.skp.shaphan.ShaphanApp"/>                <attribute name="Class-Path" value="."/>            </manifest>            <fileset dir="bin"/>            <zipfileset excludes="META-INF/*.SF" src="lib/derby.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/sqljdbc4.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/ojdbc6.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/grouplayout.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/iText-2.1.7.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/iText-rtf-2.1.7.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/iText-rups-2.1.7.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/mysql-connector-java-5.1.7-bin.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/ProjectJob.jar"/>            <zipfileset excludes="META-INF/*.SF" src="lib/jtds-1.2.5.jar"/>        </jar>    </target>
<target name="release">         <taskdef classname="net.bluecow.googlecode.ant.GoogleCodeUploadTask" classpath="lib/ant-googlecode-0.0.2.jar" name="gcupload"/>        <property file="./version.txt"/><gcupload         username="${google.code.username}"         password="${google.code.password}"         projectname="project-shaphan"         filename="project-shaphan-${major.number}.${minor.number}.jar"         targetfilename="project-shaphan-${major.number}.${minor.number}.jar"         summary="Runnable Jar File"        labels="Featured, Jar, OpSys-All" />        <propertyfile file="./version.txt">	   <entry key="minor.number" type="int" operation="+" value="1" pattern="00"/>        </propertyfile>    </target></project>

jTDS

Today, I was looking for a Sybase JDBC driver, and found this software project:

The jTDS Project

It is a open source JDBC driver for both SQL Server and Sybase.  I haven’t had much opportunity to use it, but it looks great.  They claim to be very fast.

I have started incorporating it into my query tool: Project Shaphan.

Here are some links and information to help you get started:

Here is the code that I am working with to create a link:

		try {
			Class.forName(&quot;net.sourceforge.jtds.jdbc.Driver&quot;);
		} catch (ClassNotFoundException e) {
			(new ProjectJobException(e)).displayException();
		}
		String serverType = optionsGUI.getServerType();
		String serverName = optionsGUI.getServerName();
		String portNumber = optionsGUI.getPort().trim();
		if(portNumber.length() &gt; 0) {
			portNumber = &quot;:&quot; + portNumber;
		}
		String userName = optionsGUI.getUser();
		String password = optionsGUI.getPassword();
		try {
			connection = DriverManager.getConnection(&quot;jdbc:jtds:&quot; + serverType + &quot;://&quot; + serverName + portNumber, userName, password);
		} catch (SQLException e) {
			(new ProjectJobException(e)).displayException();
		}
		ShaphanApp.getMainWindow().getSQLEditorsPane().setConnection(new ConnectionDetails(connection, ConnectionDetails.CONN_TYPE_SQL_SERVER));

Eclipse on Karmic (Ubuntu 9.10)

After installing Ubuntu 9.10, I realized that they have updated the version of Eclipse in the repositories.  So, I was able to install it with apt-get rather than download it manually.  Here is the version information from the About screen:

Eclipse SDK
Version: 3.5.1
Build id: M20090917-0800
(c) Copyright Eclipse contributors and others 2000, 2009.  All rights reserved.
Visit http://www.eclipse.org/platform

Eclipse SDK
Version: 3.5.1Build id: M20090917-0800
(c) Copyright Eclipse contributors and others 2000, 2009.  All rights reserved.Visit http://www.eclipse.org/platform

The one thing I had to add was the plugins that I use.  First, I found a blog post with instructions on adding a repository with additional plugins via packages.  To use it, add this repository to your software sources:

deb http://ppa.launchpad.net/yogarine/eclipse/ubuntu karmic main

This command will import the key:

wget http://www2.yogarine.com/eclipse-ppa.key -O- | sudo apt-key add - && sudo apt-get update

So, with that said, here are the packages that I installed:

  • eclipse
  • eclipse-rcp
  • eclipse-platform
  • eclipse-emf
  • eclipse-platform-data
  • eclipse-pde
  • eclipse-plugin-cvs
  • eclipse-wtp
  • eclipse-dtp
  • eclipse-jdt
  • eclipse-gef

Then, I added the following update sites to Eclipse.  Open the preferences with the menu: Window > Preferences.  Then, go to Install/Update > Available Software Sites.

I added Visual Swing.  See this earlier post for more information.  Here is the update site:

  • http://visualswing4eclipse.googlecode.com/svn/trunk/vs4e/

For MyLyn, I found a conversation that recommended the following two sites:

  • http://download.eclipse.org/tools/mylyn/update/e3.4
  • http://download.eclipse.org/tools/mylyn/update/extras

To install the plugins, go to Help > Install New Software.

Visual Swing

I found a nice Swing Designer for Eclipse called Visual Swing:

Eclipse Zone: Visual Swing for Eclipse

This is a project hosted on Google Code.  So far, it has worked pretty nice.  It is by no means a commercial solution, but it definitely gets the job done.

I had a little trouble installing it from the Update Site.  The first time, I just downloaded the files and manually placed them in my Eclipse Home directory.  But, today I figured out how to get the update site to work.

Here is the update site I had to use:

http://visualswing4eclipse.googlecode.com/svn/trunk/vs4e

Then, in the install window, I had to uncheck “Group items by category”.  Otherwise, it would say “There are no categorized items”.  Finally, the install window seems to have a refresh problem.  It was loading the items in the list, but it was not painting them.  I had to give it some time to load, then I had to resize the install window to make it repaint the list.

There is an outstanding bug on the Update Site: Issue #119.