Brucalipto.org

Keep your door open!

How to Create a Portable JDK 1.8 on Windows

| Comments

As a Java developer sometimes I need a version of Java Development Kit (JDK) that is not the one installed on my PC. Oracle Java installer on Windows does too many things that I cannot control (like changing the JVM used by browsers to run applets). As of this writing Java 8 is not yet available for general consumption but you can get an early access release here. Open the downloaded file with 7-zip and then open the tools.zip you find inside. Extract everything to a convenient path like C:\jdk-1.8-ea. Now it is shell time so open a DOS console (Start->Run…->cmd) and type:

Create a portable JDK 1.8
1
2
> cd C:\jdk-1.8-ea
> for /r %x in (*.pack) do C:\jdk-1.8-ea\bin\unpack200 "%x" "%x.jar"

Now you are almost done but you need to rename some files:

Look for all files that ends with .pack.jar
1
2
3
4
5
6
7
8
9
10
> dir /B /S *.pack.jar
C:\jdk-1.8-ea\jre\lib\charsets.pack.jar
C:\jdk-1.8-ea\jre\lib\deploy.pack.jar
C:\jdk-1.8-ea\jre\lib\javaws.pack.jar
C:\jdk-1.8-ea\jre\lib\jsse.pack.jar
C:\jdk-1.8-ea\jre\lib\plugin.pack.jar
C:\jdk-1.8-ea\jre\lib\rt.pack.jar
C:\jdk-1.8-ea\jre\lib\ext\jfxrt.pack.jar
C:\jdk-1.8-ea\jre\lib\ext\localedata.pack.jar
C:\jdk-1.8-ea\lib\tools.pack.jar

Rename all these files removing the .pack part (eg.: rename charsets.pack.jar to charsets.jar):

Rename all files that ends with .pack.jar
1
2
3
4
5
6
7
8
9
> ren C:\jdk-1.8-ea\jre\lib\charsets.pack.jar charsets.jar
> ren C:\jdk-1.8-ea\jre\lib\deploy.pack.jar deploy.jar
> ren C:\jdk-1.8-ea\jre\lib\javaws.pack.jar javaws.jar
> ren C:\jdk-1.8-ea\jre\lib\jsse.pack.jar jsse.jar
> ren C:\jdk-1.8-ea\jre\lib\plugin.pack.jar plugin.jar
> ren C:\jdk-1.8-ea\jre\lib\rt.pack.jar rt.jar
> ren C:\jdk-1.8-ea\jre\lib\ext\jfxrt.pack.jar jfxrt.jar
> ren C:\jdk-1.8-ea\jre\lib\ext\localedata.pack.jar localedata.jar
> ren C:\jdk-1.8-ea\lib\tools.pack.jar tools.jar

Finally test you new portable JDK 1.8:

Test portable JDK 1.8
1
2
3
4
C:\jdk-1.8-ea>.\bin\java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b121)
Java HotSpot(TM) Client VM (build 25.0-b63, mixed mode)

I hope this tutorial can help you… if you find errors please report them to me and I will correct as soon as possible.

How to Create a Portable JDK 1.7 on Windows

| Comments

As a Java developer sometimes I need a version of Java Development Kit (JDK) that is not the one installed on my PC. Oracle Java installer on Windows does too many things that I cannot control (like changing the JVM used by browsers to run applets). As of this writing Java 7 is at version u45 and you can download it from here. Open the downloaded file with 7-zip (in my case was jdk-7u45-windows-i586.exe) and then open the tools.zip you find inside. Extract everything to a convenient path like C:\jdk-1.7u45. Now it is shell time so open a DOS console (Start->Run…->cmd) and type:

Create a portable JDK 1.7
1
2
> cd C:\jdk-1.7u45
> for /r %x in (*.pack) do C:\jdk-1.7u45\bin\unpack200 "%x" "%x.jar"

Now you are almost done but you need to rename some files:

Look for all files that ends with .pack.jar
1
2
3
4
5
6
7
8
9
10
> dir /B /S *.pack.jar
C:\jdk-1.7u45\jre\lib\charsets.pack.jar
C:\jdk-1.7u45\jre\lib\deploy.pack.jar
C:\jdk-1.7u45\jre\lib\javaws.pack.jar
C:\jdk-1.7u45\jre\lib\jfxrt.pack.jar
C:\jdk-1.7u45\jre\lib\jsse.pack.jar
C:\jdk-1.7u45\jre\lib\plugin.pack.jar
C:\jdk-1.7u45\jre\lib\rt.pack.jar
C:\jdk-1.7u45\jre\lib\ext\localedata.pack.jar
C:\jdk-1.7u45\lib\tools.pack.jar

Rename all these files removing the .pack part (eg.: rename charsets.pack.jar to charsets.jar):

Rename all files that ends with .pack.jar
1
2
3
4
5
6
7
8
9
> ren C:\jdk-1.7u45\jre\lib\charsets.pack.jar charsets.jar
> ren C:\jdk-1.7u45\jre\lib\deploy.pack.jar deploy.jar
> ren C:\jdk-1.7u45\jre\lib\javaws.pack.jar javaws.jar
> ren C:\jdk-1.7u45\jre\lib\jfxrt.pack.jar jfxrt.jar
> ren C:\jdk-1.7u45\jre\lib\jsse.pack.jar jsse.jar
> ren C:\jdk-1.7u45\jre\lib\plugin.pack.jar plugin.jar
> ren C:\jdk-1.7u45\jre\lib\rt.pack.jar rt.jar
> ren C:\jdk-1.7u45\jre\lib\ext\localedata.pack.jar localedata.jar
> ren C:\jdk-1.7u45\lib\tools.pack.jar tools.jar

Finally test you new portable JDK 1.7:

Test portable JDK 1.7
1
2
3
4
> .\bin\java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Client VM (build 24.45-b08, mixed mode)

I hope this tutorial can help you… if you find errors please report them to me and I will correct as soon as possible.

The Raspberry Diary: A Case for the RPi

| Comments

As you may already know when you buy a Raspberry Pi you get only the board without any case: now it is time to dress my RPi with a new case. You can use the RPi without a case but after few days you will realise this is not good: our RPi feels so thin in our hands that a new case is a good buy to let it live as long as possible.

The search for the right case

The Raspberry Pi set new limits on what you can get for 25$: one of these limits is how much accessories have to cost. It does not make any sense buy a 50$ case for a 25$ computer and actually is quite hard to find a good looking case that is cost compatible with the RPi. Looking on the net you can find from template to print your own cardboard case (cheap but not so nice) to aluminum cases (very nice look but so much expensive). After few days I found what I think is a good compromise between cost and appearance.

RPi-Technicase

The case I found and suddenly bought is the RPi-Technicase. On the left you can see all the pieces you will find in the package they will send to you: click on the image to see a bigger picture. You will also find clear instructions to follow that are not included in the picture. All components are made from good materials: top cover and base are made in acrylic and screws, spacers, nuts and washers are metal. Mounting the whole case took about 20 minutes and it was very easy: instructions are clear and it is hard to make mistakes.

Here on the right you can see the result once the Raspberry Pi is encapsulated in its new case. As always you can click on the image to see a bigger picture.

Final considerations

I am quite satisfied about this case: it is a good looking product with the right price.

PROs

  • Good looking
  • Good instructions
  • Solid

CONs

  • The Raspberry Pi can move a bit inside the case: this is the only minor minor minor defect I can see.

The Raspberry Diary: Linksys WUSB100 Wireless N USB Adapter

| Comments

Today I want to make my Cisco Linksys WUSB100 Wireless N USB Adapter work on Raspberry Pi. In ELinux RPi Verified Peripherals page this USB Wi-Fi dongle is listed as problematic and making it to work is quite a challenge. My own USB key is exactly the one listed there with idVendor=”1737” e idProduct=”0078” identified as Linksys (Cisco) WUSB100 ver.2.

Software installation

As I noted in my previous post I’m using Raspbian, the Linux distribution recommended in the Raspberry Pi official download page. For using the Wi-Fi USB key we need at least the software for managing Wi-Fi networks and the firmware for the USB Wi-Fi key: specifically the WUSB100 ver.2 is based on the RT-3070 Ralink chipset. This USB key is supported by the rt2800usb driver actually present in the official Raspberry Pi linux kernel once you provide the firmware binary blob. All the following commands must be run as root.

So let us install the needed packages:

1
$ apt-get install wireless-tools wpasupplicant firmware-ralink

Software configuration

Now we have all the needed software but still the Wi-Fi USB will not appear as device wlan0 we need to make it working: it is time of some udev voodoo and finally things should work.

First we need to edit file /etc/udev/rules.d/network_drivers.rules

1
$ nano /etc/udev/rules.d/network_drivers.rules

and then add as a single line the following:

1
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1737", ATTR{idProduct}=="0078", RUN+="/sbin/modprobe -qba rt2800usb"

Double check you wrote it right, save and close. Then we need to edit /etc/modprobe.d/network_drivers.conf

1
$ nano /etc/modprobe.d/network_drivers.conf

and then add the following as a single line:

1
install rt2800usb /sbin/modprobe --ignore-install rt2800usb $CMDLINE_OPTS; /bin/echo "1737 0078" > /sys/bus/usb/drivers/rt2800usb/new_id

Network setup

Finally you need to modify /etc/network/interfaces to reflect the new interface addition adding something similar to:

A possible interfaces if Wi-Fi is WEP encrypted
1
2
3
4
5
6
# my wifi device
auto wlan0
iface wlan0 inet dhcp
  wireless-essid [ACCESS_POINT_SSID]
  wireless-mode Managed
  wireless-key [YOUR_SECRET_WEP_PASSWORD]

or

A possible interfaces if Wi-Fi is WAP encrypted
1
2
3
4
5
# my wifi device
auto wlan0
iface wlan0 inet dhcp
  wpa-ssid [ACCESS_POINT_SSID]
  wpa-psk [YOUR_SECRET_WPA_PASSWORD]

If you write your password in /etc/network/interfaces please keep it permission tight:

1
$ chmod 0600 /etc/network/interfaces

Reboot and final checks

Now reboot and everything should be fine: finally you will see the wlan0 device appearing if you run ifconfig:

1
$ ifconfig -a

With all these steps my Cisco Linksys WUSB100 Wireless N USB Adapter is working and stable during last 8 hours with moderate network traffic: I did not stress test it yet… if I will found something unusual I will let you know.

Is this setup working for you? Do you have any problem? Use comments below to leave a feedback and I will try to help you!

The Raspberry Diary: Let’s Start

| Comments

Unless you live under a rock you should know about the existence of the Raspberry Pi, the ARM GNU/Linux box that costs only $25! It is a technological and economical marvel smaller than a packet of cigarettes. I just received my sample and from now on I will write about my experience with this nice gadget.

First things first

The first thing to do is to start the Raspberry Pi: for 25$ you get only the barebone board you can see in the picture on the right. For a somewhat complete list of supported peripherals you can take a look at Elinux site.

For my raspberry I then used:

  • Samsung 8GB Class 10 SDHC - Model code: MB-SP8GA/EU
  • Microsoft Wireless Optical Desktop 700 (mouse and keyboard)
  • Linksys by Cisco WUSB100 Wireless N USB Adapter (for wi-fi network)

For the operating system I opted for Raspbian minimal image you can find here. Install it on the SD following the instructions reported there… I had no problems, everything was clear and it worked fine.

The only problem found so far is the wireless usb key that is not working as expected… this is going to be material for the next installment.

Singleton Pattern: SingletonHolder

| Comments

Writing a singleton is not that hard but writing it the right way may not be all that trivial. I wrote hundreds singletons in my developer life and yesterday I found, thanks to a Wikipedia post, what I think is the perfect solution. The solution is not mine but I report it here for future reference:

Singleton.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class Singleton
{
  // Private constructor prevents instantiation from other classes
  private Singleton(){}

  /**
  * SingletonHolder is loaded on the first execution of Singleton.getInstance() 
  * or the first access to SingletonHolder.INSTANCE, not before.
  */
  private final static class SingletonHolder
  {
      private final static Singleton instance = new Singleton();
  }

  public static Singleton getInstance()
  {
      return SingletonHolder.instance;
  }
}

In this implementation the singleton instance is thread safe and unique as this is warranted by using final and static keywords. Moreover the singleton instantiation is as lazy as possible: the singleton instance will be created if and only if you call the getInstance() method and not whenever you simply reference the Singleton class (like accessing a constant).

VMware Player 4.0.1 Announced

| Comments

VMware has just announced the release of the updated VMware Player. VMware Player is the free product from VMware to perform virtualization on desktop PC. The release 4.0.1 follows the version 4.0.0 released at the beginning of October.

You can find release notes for VMware Player 4.0.1 here.

How to Install GOsa on RHEL or CentOS 5

| Comments

As you can read on GOsa website: “GOsa² provides a powerful GPL’ed framework for managing accounts and systems in LDAP databases. Using GOsa² allows system administrators to easily manage users and groups…”. The installation on Red Hat Enterprise Linux/CentOS is a bit tricky and here you will find how to install it.

First you need to set SELinux in permissive mode (if you have enabled it) and configure the firewall to let other systems to connect to port 80/443 (HTTP and HTTPs) and 389 (LDAP server port) using the commandline tool

Setting firewall
1
$ system-config-securitylevel-tui

Now we need to get some more RPM repos to work:

Adding more rpms repos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//First the CentOS testing repo
$ cd /etc/yum.repos.d/
$ wget http://dev.centos.org/centos/5/CentOS-Testing.repo
//Then the RPMForge repo
$ rpm -Uhv \
  http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
//And last the GOsa RPM repo
$ cat >> GOsa.repo << EOF
[GOsa-Repository]
name=GOsa Repository
baseurl=ftp://oss.gonicus.de/pub/gosa/redhat
enabled=0
gpgcheck=0
EOF

As we want the system as stable as possible without many packages from externarl repositories please verify that the files CentOS-Testing.repo and rpmforge.repo both contain the line ’enabled=0’. Now let’s check the new repositories for new packages to install and install them:

Installing packages
1
2
3
4
5
6
7
8
9
10
11
12
13
$ yum --enablerepo=rpmforge,GOsa-Repository,c5-testing check-update
//Install LDAP
$ yum install openldap openldap-servers
//Install PHP 5.2 from CentOS Testing
$ yum --enablerepo=c5-testing install php-common php-imap \
  php-snmp php-mysql php-mbstring php-pdo
//Install perl-Crypt-SmbHash from RPMForge
$ yum --enablerepo=rpmforge install perl-Crypt-SmbHash
//Install GOsa RPMs
$ yum --enablerepo=GOsa-Repository install gosa-help-en.noarch \
  gosa-plugin-addressbook.noarch gosa-plugin-ldapmanager.noarch \
  gosa-plugin-mail.noarch gosa-plugin-rolemanagement.noarch \
  gosa-plugin-systems.noarch gosa-schema.noarch gosa-plugin-goto

Now we need to be sure that Apache HTTPD and LDAP servers start at boot:

Starting services
1
2
3
4
$ chkconfig httpd on
$ chkconfig ldap on
$ service httpd start
$ service ldap start

At this point, before configuring GOsa, you need to add specific GOsa schemas to your ldap using as reference a part of the beginning of my own /etc/openldap/slapd.conf

LDAP configuration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/gosa/rfc2307bis.schema
include /etc/openldap/schema/gosa/gofax.schema
include /etc/openldap/schema/gosa/gofon.schema
include /etc/openldap/schema/gosa/samba.schema
include /etc/openldap/schema/gosa/gosystem.schema
include /etc/openldap/schema/gosa/goto.schema
include /etc/openldap/schema/gosa/samba3.schema
include /etc/openldap/schema/gosa/gosa-samba3.schema
include /etc/openldap/schema/gosa/goserver.schema
include /etc/openldap/schema/gosa/goto-mime.schema
include /etc/openldap/schema/gosa/trust.schema

Restart your openldap and finally we can connect to GOsa web interface and configure it pointing your browser at:

1
http://<hostname>/gosa/

Now you should have a fully functional GOsa install on your CentOS5: please let me know if you found error in this tutorial or even if you found it useful.

Windows Port Forwarding

| Comments

In Linux world port forwarding is a common feature: if you need to forward traffic from port XX to port YY you simply use the integrated Linux firewall called iptables. In Microsoft Windows the integrated firewall is not so sophisticated as the Linux one and I needed to found a solution. A friend of mine was asked about this question and answered: “You cannot find anything working… if you find something let me know!”.

The smartest solution I found was to use stunnel: maybe an overkill software for this simple task but it is 1. well known and opensource; 2. stable; 3. works as a windows service.

My own problem was to forward SMTP traffic from port 65025 to the well known port 25: this way if I telnet to port 65025 I can speak directly with the SMTP server listening on port 25.

The first thing was to download stunnel for windows and install it.

Now all the magic is to write the appropriate stunnel.conf file that, in my case, was something like this:

stunnel configuration file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
; Certificate/key is needed in server mode and optional in client mode
; The default certificate is provided only for testing and should not
; be used in a production environment
cert = stunnel.pem
; Some performance tunings
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
[in65025smtp]
accept = 10.145.2.88:65025
connect = 10.145.2.88:65024
protocol = smtp
client = yes
[out25smtp]
accept = 10.145.2.88:65024
connect = 10.145.2.88:25
protocol = smtp

Looking at the stunnel.conf file provided you can see the trick: stunnel accept SMTP connections on port 65025 and encrypts them forwarding the traffic to port 65024; then it gets encrypted SMTP traffic from port 65024 and forwards it decrypted to port 25.

Last but not least is to register stunnel as service: in Windows this is as easy as 1, 2, 3

Please remember also to start the service ;)

I hope this is clear… if you find something wrong here please let me know and I will correct it!