Friday, June 22, 2012

Oracle (sun) java 6 install

I am currently running Mint Linux 13 which comes with OpenJDK/JRE but I require Oracle(Sun) Java here is how to install manually.  I know there are PPA's out there but I do not find them very reliable since Oracle seem to have some licensing issue with 3de parties hosting Java binaries.

Step 1: Download

Go to the Oracle site and select your Java. http://www.oracle.com/technetwork/java/javase/downloads/index.html

Step 2: Extract

I downloaded Java 7 JDK so to extract was simply

 tar -xvf ~/Downloads/jdk-7u5-linux-x64.tar.gz  

Step 3: Move

When you install Java via a package manager for a Debian system the install location is /usr/lib/jvm/.  If you go have a look at that folder you should see all the installed version of java on you pc.  So to move the extracted folder:

 sudo mv ~/Downloads/jdk1.7.0_05 /usr/lib/jvm/java-7-sunjdk  

This will move and rename the folder to java-7-sunjdk

Step 4: Install

Linux has this amazing command to where you can link commands with the option of easy switching.

So to list all the currently installed options for the command java type

 user@user-SERVER ~ $ sudo update-alternatives --list java  
 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  

As you can see here I only have Java 6 OpenJDK installed for the command java.  Now to add my Oracle java I will have to install a new option as follow:

 sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-7-sunjdk/bin/java" 1  

Now if I rerun the list command I have two options for the java command

 user@user-SERVER ~ $ sudo update-alternatives --list java  
 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  
 /usr/lib/jvm/java-7-sunjdk/bin/java

Step 5: Select Default

Now to select which one must be executed by default if I run the java command:

 user@user-SERVER /usr/lib/jvm $ sudo update-alternatives --config java  
 There are 2 choices for the alternative java (providing /usr/bin/java).  
  Selection  Path                      Priority  Status  
 ------------------------------------------------------------  
 * 0      /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  1061   auto mode  
  1      /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  1061   manual mode  
  2      /usr/lib/jvm/java-7-sunjdk/bin/java       1     manual mode  
 Press enter to keep the current choice[*], or type selection number: 2  
 update-alternatives: using /usr/lib/jvm/java-7-sunjdk/bin/java to provide /usr/bin/java (java) in manual mode.  

When you run this command you are show the current default and all the available options.  In my case I selected option 2 as my new default.

Step 6: Jippy

Your all done below are just some command for the ease to map the javaws, javac and jps.  Your more than welcome to add more.

 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-7-sunjdk/bin/javac" 1  
 sudo update-alternatives --config javac  
 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java-7-sunjdk/bin/javaws" 1  
 sudo update-alternatives --config javaws  
 sudo update-alternatives --install "/usr/bin/jps" "jps" "/usr/lib/jvm/java-7-sunjdk/bin/jps" 1  
 sudo update-alternatives --config jps  

Wednesday, May 16, 2012

Ivy Bridge HD4000 Linux Freeze

First thing I did after I received my new Ivy Bridge PC with Gigabyte GA-Z77-D3H and Intel Core i7 3770 was install the new Ubuntu 12.04.  All was fine for a while until the PC would freeze up, mouse not moving, ATL+CTRL+F1 not working, nothing!  This seemed to happen every-time semi heavy load was placed on the HD 4000 graphics processor on the i7 chip.  Something I found that really triggered this was browsing websites like Google maps or scrolling up and down on a page with lots of dynamic content in Firefox it is a guaranteed freeze.

After a bit of trail and error the solutions was found.  There seems to be a bug in the Linux Kernel 3.2.x.  Now after upgrading to Kernel 3.3.x the problem has disappeared!  Below are the steps to update the kernel in Ubuntu 12.04.

Please note I do not take any responsibility if this breaks things.  This worked for me and I am merely trying to help others.

At the time of writing this article the latest stable kernel is 3.3.6

The kernel can be found at kernel.ubuntu.com or you can just ignore this and copy and past the commands below to the terminal depending on you installation

For Ubuntu (i386 / 32-bit) run these commands
 cd /tmp && wget -O linux-headers-3.3.6-030300_3.3.6_all.deb http://goo.gl/zNlMy  
 sudo dpkg -i linux-headers-3.3.6-030300_3.3.6_all.deb  
 cd /tmp && wget -O linux-headers-3.3.6-generic_i386.deb http://goo.gl/TdBex  
 sudo dpkg -i linux-headers-3.3.6-generic_i386.deb  
 cd /tmp && wget -O linux-image-3.3.6-generic_i386.deb http://goo.gl/osZhw  
 sudo dpkg -i linux-image-3.3.6-generic_i386.deb  

For Ubuntu (amd64 / 64-bit) run these commands
  cd /tmp && wget -O linux-headers-3.3.6-030300_3.3.6_all.deb http://goo.gl/zNlMy  
 sudo dpkg -i linux-headers-3.3.6-030300_3.3.6_all.deb  
 cd /tmp && wget -O linux-headers-3.3.6-generic_amd64.deb http://goo.gl/Z9Ztt  
 sudo dpkg -i linux-headers-3.3.6-generic_amd64.deb  
 cd /tmp && wget -O linux-image-3.3.6-generic_amd64.deb http://goo.gl/jji3o  
 sudo dpkg -i linux-image-3.3.6-generic_amd64.deb 

Just reboot your system and done.

I you have any questions/problems please leave a comment and I will try to help

Friday, April 20, 2012

Seam parameter as date

When using Seam Gen to setup basic pages from the persistence objects where a primary key is a date or one of the keys in the combined primary key is a date you will run into this error:  "value must be a date"

 This is due to the date converter not working properly when seam is parsing the page parameters.  By default it just performs a toString causing the page parameter to be populated as follow:

ReadDate=2007-01-02+00%3A00%3A00.0


The fix for this is easy just add a SimpleDateFormat or if you using JodaTime a DateTimeFormatter to output a string version of the date on the hibernate object as show below:


public String getReadDateStr() {

  // SimpleDateFormat
  return new SimpleDateFormat("dd/MM/yyyy").format(date)
  // Joda Time
  return DateTimeFormat.forPattern("dd/MM/yyyy").print(date.getTime())



Then in the JSF change the parameter as follow:
<f:param name="startDate" value="#{_priceElementRate.id.readDateStr}" />




Sunday, March 18, 2012

5x5 LED Cube

The 5x5 LED cube project version 1.0 is working!



I am making use of 4 shift registers 74CH595N to control the 25 columns and 5 P2N2222A NPN Transistor to select a layer.  Currently I am writing the cube state for a layer out every 7ms.

The soldering of the cube was painful, but at least now I regained a bit of the soldering iron skill that I lost since uni.  Below are some pics of the building of the cube:



 But I must say the most fun of the project was the coding, really enjoyed playing with C again.  My next step will be to port this project from the ATmega328 chip (Arduino) to the MSP-EXP430G2 chip (TI Launchpad).

Monday, March 5, 2012

JBoss and debug breakpoints

The problem

Got in on a Monday morning ready to write some code.  Start up the JBoss server via JBoss tools, but it just freezes after a while.  Works perfectly with debug arguments.  So I started the server via the bin/debug.sh command and connected Eclipse to the JBoss server.  As soon as I connected to the server it froze and when I disconnected everything went back to normal...

The Solution

Debug breakpoint in a EJB causes a heavy overhead to JBoss startup.  And that is exactly what I did had a breakpoint left in from the previous week.  So remove all breakpoints when you have finished debugging!

Wednesday, February 29, 2012

Packet drops in Ubuntu and Fedora with Realtek NIC driver r8169

The Problem
I recently purchased a Gigabyte GA-Z68X-UD4-B3 motherboard, installed Ubuntu and started to download eclipse.  The download took forever!  Tried to open a few websites and some of them just timed out.  I was just about to get on the phone with the ISP when I noticed doing a ping the router some packets where being lost!


The solution
The motherboard comes with a Realtek network card running the r8169 chip.  Now for some reason Ubuntu and Fedora detects this as a r8168.

To check this run:
lsmod | grep r8168
If you get a output if means your using the r8168 driver instead of the r8169.

Step one is to download the driver required from Realtek
http://www.realtek.com.tw/downloads/downloadsView.aspx?Langid=1&PNid=13&PFid=5&Level=5&Conn=4&DownTypeID=3&GetDown=false

Once the download is complete extract
tar vjxf r8168-8.tar.bz2
The next step will disable the network interface, remove the r8168 module.
sudo rmmod r8168
Now run the autorun.sh file in the extracted folder
sudo ./autorun.sh
Blacklist the r8168 module form being loaded again you will have to add it to the blacklist
sudo gedit /etc/modprobe.d/blacklist.conf
Add the following line:
blacklist r8169
Update the driver cache
sudo update-initramfs -u
Now to check that everything went according to plan run
lsmod | grep r8168
If you get a output your done and dusted!

Monday, February 27, 2012

LXDE HDMI as default audio output device

The Problem:

If you are have a old pc running a lightweight linux interface like LXDE or XFCE, e.g LUbuntu and need to get the audio out to work via the HDMI you most probably have notices there is not a nice GUI to do this like in Ubuntu.

The Solution:

pavucontrol is a great and simple solution.  I know it is a bit heavyweight since you have to install pulseaudio but it is the easiest solution I have found.  To install:
sudo apt-get install pulseaudio pavucontrol
then to run
pavucontrol

Thursday, February 16, 2012

Cannot create Seam component, scope is not active


The problem:

I kept on running into to following error:
WARN  [org.jboss.seam.Component]  Cannot create Seam component, scope is not active: mySuperAction(CONVERSATION)
SEVERE [javax.enterprise.resource.webcontainer.jsf.lifecycle] JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: /ThePage.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@19da36b]

Seam said my long-running conversation was gone.  But how could this be!  Well after a lot of digging I found this hidden line in the Seam documentation:

Conversational components have one minor limitation: they cannot be used to hold bindings to JSF components. 

What I was doing is I had a DataTable binding in the JSF.  The reason for this is I was not sure what columns or data was going to be displayed for the datatable until the time the page was being generated.

The solution:


As stated in the documentation, move and the HtmlPanelGrid in a new container with scope set to EVENT.
@Name("grid")
@Scope(ScopeType.EVENT)
public class Grid
{
    private HtmlPanelGrid htmlPanelGrid;

    // getters and setters
    ...
}@Name("mySuperAction")
@Scope(ScopeType.CONVERSATION)
public class MySuperAction
{
    @In(create=true)
    private Grid grid;
   
    private void populateTable(){....}

 }
Add to the page.xml a new action that calls the populateTable:
<action execute="#{mySuperAction.populateTable}" />
Now for the binding:
<h:panelGroup id="dynamicTablePanel" binding="#{grid.htmlPanelGrid}" />
Just as a note I found in a few forum posts where made where they stated adding getters and setters for the Grid on the MySuperAction thus making the binding look like this:

 <h:panelGroup id="dynamicTablePanel" binding="#{mySuperAction.grid.htmlPanelGrid}" />
This will work until you do your first AJAX call on the page and you will be hit with a nice RESTORE_VIEW error.