ClassNotFoundException running applets when updating to Java7 jre

One day I got this message that said ”do you want to update java to the latest version”, which I then accepted. However, after the update everything ”java” running in Internet Explorer and Firefox stopped working. The testpages (JavaTest 1,
JavaTest 2) did not work, all they said was ”JavaVersionDisplayApplet.class ClassNotFoundException” and ”testjava2_1.testvmapplet.class ClassNotFoundException”.

I then tried to uninstall and reinstall everything Java on my Windows 7 64-bit machine. Tried both the 32 and 64 bit Java version, tried both the jdk and the jre. Nothing worked! After a couple of hours I found this thread that lead me in the right direction.

Solution
1) Go to the ”windows control panel” and press the Java icon. Alternatively, go to your jre folder and execute ”javacpl.exe”. If you have multiple jre’s installed then only change one of them because I think they overwrite eachothers settings.

2) Go to the Java-tab and change ”settings for java runtime environment”. Add ”-Djava.net.preferIPv4Stack=true” to the run paramaters for your jre. When you are done with this step it should work again. Restart your browser and test your java.

It should look like this (in swedish)
jre-control-panel

3) If you are still having problem, check the ”network settings” in the java control panel.

4) A good way to ”debug” java jre trouble like this is to enable the java console. This can be done in the ”advanced” tab of the java control panel. By enabling the console you get a window which shows valuable debug information.

I think this problem is somehow related to our network at work which is IPv6 enabled. Or perhaps it is our VPN that uses IPv6. Well, I have given this problem to much attention. Back to work…

Strange errors running java7 on IPv6 wifi connection

Today I was developing at work as usual at work, however I used the wifi connection because the cabled network was not working. My first problem for the day was that Eclipse could not connect to repositories when trying to install new software. All I got was ”permission denied” errors and…

org.eclipse.equinox.p2.core.ProvisionException Unable to read repository at http://download.eclipse.org/releases/indigo/content.xml

Solution: Add ”-Djava.net.preferIPv4Stack=true” to eclipse.ini

My second problem was that I got really strange errors from my local Resin Application Server. It could not connect to my local SQl-server.

Solution: Add ”-Djava.net.preferIPv4Stack=true” to Resin jvm start arguments

My conclusion is that because our wifi network uses IPv6 then Java uses that instead of IPv4 if not clearly stated. And the applications that I was using was not ”configured” for IPv6 usage.

LazyInitializationException: could not initialize proxy – no Session

The error ”org.hibernate.LazyInitializationException: could not initialize proxy – no Session” has been giving me a headache for the last couple of days. So many people on the Internet have different answers and solutions to this error. The web-app that I am working on is made with Java + Resin + Spring + Hibernate + JSP + Stripes. This error occurs when the session is no longer active.

Add this to your web.xml file and sessions should be open during the entire request.


<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Works for me! Read more about OpenSessionInViewFilter

Sun Certifierad Java Programmerare (SCJP)

Det har inte blivit något skrivet här på sistone eftersom jag pluggat frenetiskt de senaste veckor för att certifiera mig inom programmeringsspråket Java. Idag skrev jag provet hos Cornerstone i Sundsvall och klarade det. Jag fick 68% rätt på de 72 frågorna, där gränsen var 59%. Yippie, fy fan vad jag fick slita…

Nu är jag alltså certifierad java utvecklare enligt Sun. Nästa mål är att certifiera mig som Microsoft Certified Technology Specialist (MCTS) i .NET Framework 2.0.

Detta ska firas i helgen!

champagnebottle

Unix timestamp in C#, Java and php

For some strange reason the Dotnet framework has no conversion between a unix timestamp and a DateTime. Or has it? Why is it so when the framework has billions of other stuff that you never use. This functionality is actually something you would normally use in a system that communicates with the outside world.

This webpage has a solution
Another page about the same stuff

In my current project I am trying to convert a Java Calendar object to a C# DateTime through JNI (Java Native Interface). I have no perfect solution at this moment but I will try to use a unix timestamp though I am losing some precision.

Java has direct conversion from Calendar to Date (which is a representation of a unix timestamp). Bravo! :-)

php has lots of functions (like timetostr, time) to create and convert unix timestamps.