Sun has published milestone 5 (b76) of the upcoming Java JDK 7. JDK 7 release is currently scheduled for September 2010. My standard IDE is eclipse but the current production version 3.5 SR 1 support only Java up to JDK 6. I tried the new eclipse e4 1.0 milestone 2 (status: technical preview) which has JDK support up to JDK 7. You can define a JDK 7 as new JRE and create a new Java project with that JRE and compiler compliance level JDK 1.7. According to Joseph Darcy from SUN is a developer build of Netbeans available with support for JDK 7. I tested with code from CertPal which includes several features of JDK 7. Eclipse e4 still complain about compiler errors but the developer build of netbeans can compile and run the sample code. Check in netbeans under tools -> Java platform the availability of JDK 7 and create a new java project. Set in the java project under properties the source/binary format to jdk 1.7 (sources tab) and choose as java platform JDK 1.7 (libraries tab). On OpenJDK is a overview of the current implemented features of JDK 7 in the M5 version. Mark Reinhold from sun blogs as well about the new features. A more complete list of features which was formerly planned shows Alex Miller in his blog.
Monthly Archives: November 2009
Spring 3.0 RC 2 and JSR-330 (Dependency Injection for Java)
SpringSource has published release candidate 2 of the upcoming 3.0 release of their Spring Framework. New Feature is the compliance with JSR-330 (“Dependency Injection for Java”). The JSR was developed together by Google (for their Guice Framework and SpringSource (for their Spring Framework) and is finally approved since 14.10.2009.
A little example shows how to develop services with interfaces and implementations without dependencies to Spring Framework or Google Guice:
The Maven pom.xml
4.0.0 de.schaeftlein.dev jsr330-sample jar jsr330-sample 0.0.1-SNAPSHOT Sample App with Spring 3.0 RC 2 and JSR330 3.0.0.RC2 org.springframework spring-core ${springVersion} org.springframework spring-beans ${springVersion} org.springframework spring-context ${springVersion} org.springframework spring-asm ${springVersion} org.springframework spring-expression ${springVersion} junit junit 4.7 test javax.inject javax.inject 1 jsr330-sample src/main/java ${basedir}/src/test/java src/main/resources **/.svn **/.svn/** **/_svn _svn **/_svn/** src/test/resources **/.svn **/.svn/** **/_svn _svn **/_svn/** org.apache.maven.plugins maven-compiler-plugin 1.6 org.apache.maven.plugins maven-eclipse-plugin true true _svn .svn org.apache.maven.plugins maven-jar-plugin true org.apache.maven.plugins maven-source-plugin attach-sources verify jar
a simple encode/decode interface
package de.schaeftlein.dev.spring; public interface Encryption { String encode(String value); String decode(String value); }
a simple implementation for Encryption
package de.schaeftlein.dev.spring; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import javax.inject.Named; @Named // service name is the name of the class public class URLEncoderEncyrption implements Encryption { @Override public String decode(String value) { try { return URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { return null; // never happen } } @Override public String encode(String value) { try { return URLEncoder.encode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { return null; // never happen } } }
a more secure implementation for Encryption
package de.schaeftlein.dev.spring; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import javax.inject.Named; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import com.sun.org.apache.xml.internal.security.utils.Base64; @Named("secure") // named service bean public class Base64Encyption implements Encryption { private sun.misc.BASE64Encoder base64encoder; private SecretKey key; public Base64Encyption() { try { DESKeySpec keySpec = new DESKeySpec("Your secret Key phrase".getBytes("UTF8")); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); key = keyFactory.generateSecret(keySpec); base64encoder = new BASE64Encoder(); } catch (Exception e) { e.printStackTrace(); } } @Override public String decode(String input) { try { Cipher cipher = Cipher.getInstance("DES"); // cipher is not thread safe cipher.init(Cipher.DECRYPT_MODE, key); byte[] bOut = cipher.doFinal(Base64.decode(input.getBytes("UTF-8"))); return new String(bOut, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } return null; } @Override public String encode(String plainTextPassword) { try { byte[] cleartext = plainTextPassword.getBytes("UTF8"); Cipher cipher = Cipher.getInstance("DES"); // cipher is not thread safe cipher.init(Cipher.ENCRYPT_MODE, key); return base64encoder.encode(cipher.doFinal(cleartext)); } catch (Exception e) { e.printStackTrace(); } return null; } }
a small interface for a service
package de.schaeftlein.dev.spring; public interface SecureUtil { void compareEncryption(String input); }
a implementation for our service
package de.schaeftlein.dev.spring; import javax.inject.Inject; import javax.inject.Named; @Named("SecureUtil") public class SecureUtilImpl implements SecureUtil { @Inject // automatically set by DI framework @Named("secure") // get the namend bean private Encryption secureEncryption; @Inject // automatically set by DI framework @Named("URLEncoderEncyrption") // get the bean by its classname private Encryption unsecureEncryption; public void compareEncryption(String input){ String encodedSecure = secureEncryption.encode(input); System.out.println("Secure encoded: "+encodedSecure); String encodeUnsecure = unsecureEncryption.encode(input); System.out.println("Unsecure encoded: "+encodeUnsecure); System.out.println("Secure decoded: "+secureEncryption.decode(encodedSecure)); System.out.println("Unsecure decoded: "+unsecureEncryption.decode(encodeUnsecure)); } }
finally a main class for testing
package de.schaeftlein.dev.spring; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Main { /** * main method */ public static void main(String[] args) { ApplicationContext ctx = new AnnotationConfigApplicationContext(Main.class.getPackage().getName()); // new way to get Application context without applicationContext.xml available SecureUtil util = ctx.getBean("SecureUtil", SecureUtil.class); // get bean with new generics method util.compareEncryption("an sample input string 1234567890"); } }
output of our Main class
19.11.2009 18:56:03 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@c1b531: startup date [Thu Nov 19 18:56:03 CET 2009]; root of context hierarchy 19.11.2009 18:56:03 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorINFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 19.11.2009 18:56:03 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@a83b8a: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,secure,SecureUtil,URLEncoderEncyrption]; root of factory hierarchy Secure encoded: QDQvd4uK14YNUQ4uoqhqsZEMDDxUqJAMyisvZr2wsA2GyMC5tSEIiw== Unsecure encoded: an+sample+input+string+1234567890 Secure decoded: an sample input string 1234567890 Unsecure decoded: an sample input string 1234567890
Chrome OS 0.4.237 beta under vmware server 2.x
A beta version of Chrome OS is available as VMX/VMDK image for vmware or virtualbox and live cd. Chrome OS is a OpenSuSe based operating system around the Google Chrome browser.
Steps to test VM image of chrome os beta
- Download VMDK image
- Extract tar.gz File to standard folder of vmware
- Start vmware server
- Choose from “Virtual machine” menu “add Virtual machine to inventory”
- Choose VMX file inside extracted image of chrome os
- Upgrade Virtual machine to newest “hardware” by choosing link on right side from the vm summary page
- Remove Network Connection from VM and Add new one with “Add Hardware” and type “Network Adapter” with “Nat” mode
- Boot VM and cornfirm warning about IDE geometry and scsi controller
- Click on “Make Goggle chrome default browser” and confirm dialog
- Click on computer button (down left side) and click under status on network connection
- Enter root password: root
- confirm warning about network manager with ok
- Choose under “Global Options” network setup method “traditional method with ifup”
- Go to “Overview” tab and click on “edit” button below
- click on “next” button
- go back to “global options” and change back to “user controlled with networkmanager”
- Reboot machine by clicking on computer and shutdown with type reboot
- After reboot you can surf with google chrome without any problem
Convert VMWare 2.x Image to VirtualBox 3.x (seamless mode)
Windows 7 Home Premium has no XP Mode Feature like in Pro or Ultimate Edition to run an Windows XP virtual machine seamless. Home Premium can be upgraded by Anytime Upgrade within Windows to Professional or Ultimate (90$* or 140$*). You need at least Professional Version for XP Mode. So i looked for alternatives. Under Windows XP was VMWare server 2.x my first choice without seamless mode. Seamless Mode made VM windows be available in host OS as “normal” windows without the rest of the VM OS. One Alternative is VMWare Workstation 7 with seamless mode (176€*). Paralells has currently an beta version available with Coherence (seamless) feature. Virtualbox as open source alternative has seamless mode too. You need only to install the guest additions of virtualbox, reboot after installation and call from menu “seamless mode”.
So i give Virtualbox a try and installed the current 3.0.10 version under Windows 7. VirtualBox can work with VMware VMDK Hard disks out of the box.
Steps to convert from VMware to Virtualbox:
- Start VMware image under VMware
- Uninstall VMware Tools inside VM
- Shutdown VM
- Open DOS command shell in VM folder
- set path variable to include VMWare server folder: set path=
;%PATH% - convert splitted VM hard disk to single file: vmware-vdiskmanager -r source_multiples.vmdk -t 2 single_file.vmdk (use ” to surround file name if file name contains spaces)
- copy new single_file.vmdk and single_file-flat.vmdk to
\harddisks on host os with virtualbox - Start VirtualBox under host OS
- Open in file menu “Virtual media manager”
- Go to “Hard Disks” tab
- Click on Add Button and choose single_file.vmdk
- Close dialog with OK button
- Click on “New” button to create a new VM
- Click on “Next” button
- Enter name for new VM and choose operation system including version (in my example Win_vista” as name, “Microsoft Windows” as OS and “Windows Vista” as version)
- Set memory to a suitable value (on my machine i prefer 512MB for good enough performance)
- On the next page choose “Use existing hard disk” and select from Drop down the old VMware hard disk image
- Click on Finish
- Open Settings of new VM to correct problems with different hard ware in VMware and VirtualBox
- Go to System => Motherboard and “enable IO APIC”
- a had an scsci lsi logic controller under VMware: Go to “Hard Disks” and “Enable Additional Controller” including selection of “SCSI (Lsilogic)”s
- Start new VM
- Install Virtualbox guest additions from vm window menu under “Devices”
- reboot vm
- Start for example a IE windows inside vm and call from “Machine” menu “seamless mode”
Currently that doesn’t seems to work with windows vista. Another VM in virtualbox with windows XP Professional works as expected in seamless mode.
Keep in mind that such a migration with Windows Vista as guest os needs another activation because of changed multiple hardware components.
Another possibility is to install the unofficial Virtual PC 6.1 for windows 7 from the knowledge base (32bit / 64bit). As described here you see in the windows 7 start menu the entries of the installed programs under the xp vm to start them directly in seamless mode. Comparing to the windows 7 XP mode their is the requirement for a separate windows xp license for a windows home or starter host os. Windows 7 professional or ultimate include such a license for a virtual windows xp on the same machine. Virtual PC needs a Virtualization hardware support like intel VT-X or AMD-V. The installation of Virtual PC fails if the processor and mainboard don’t fit to this requirement.
Startmenu entry of Virtual PC
Start installed Apps inside XP VM from Windows 7
Seamless started XP VM Application under Windows 7
*Price are only snapshots from the manufacturer websites without any guarantee and only provided to compare the possibilities.