Posts Tagged ‘Java’

Published JavaDocSuppressor or jadosu v1.0 to github

Saturday, August 25th, 2012

So every so many time I come across some Java code that’s littered with useless JavaDoc comments that do nothing more than obfuscate what the code actually does. So when I found myself looking for the same set of regular expressions yet again I thought it wise to finally automate it.
The binary downloads as well as the Java sources can be found on github. The whole is available under the Apache License 2.0.

Rather than modifying the original sources, the modified sources are stored at a designated  directory path which will be created. Unmodified sources can be optionally included as well by provided the ‘-i’ argument, effectively resulting in a full copy of the source path with modified sources.

Grab it here

Sending email to your SSL/TLS enabled smtp with Spring from WAS/Glassfish

Monday, February 28th, 2011

So what I needed to accomplish:

  • send automated emails from a webapp using Spring 3.0
  • running on a Glassfish / WAS  instance
  • to an SSL/TLS secured SMTP (smtps) service running on a different host

Import the certificate

First of all, we need our jvm to trust the certificate of the remote host that offers the smtps service which in my case is available on port 465 (which is common).

To do that, first of all read Andreas Sterbenz’ old Sun blog post regarding the InstallCert tool he wrote.

Download InstallCert.java to some directory, move to that dir, and run
javac InstallCert.java

Next, run
java InstallCert

from the same dir to get usage instructions.

I went for the version
java InstallCert your.host.com:your_port

After selecting the certificate you want to add to the trusted keystore by pressing the associated number you’ll end up with a file called jssecacerts in your working directory.

Also note the last line of the generated output, which should be something along the lines of:
Added certificate to keystore ‘jssecacerts’ using alias ‘your.host.com-1′

You’ll need that alias for the next step.

Export the certificate from the keystore file ‘jssecacerts’

To do this we’ll use keytool, note the alias name which needs to be equal to the one mentioned in the last step:

keytool -export -alias your.host.com-1 -keystore jssecacerts -file my_actual_cert.cer -storepass changeit

We now have a file representing the actual certificate we need to trust in order for our application to be able to set up a secured connection with your.host.com

Importing the certificate

Before we get to use keytool again, make sure you have proper permissions to modify your JRE installation and go to
<jre_root>/lib/security

Eg. for the Sun (Oracle) JDK on Debian/Ubuntu <JRE_ROOT> could be
/usr/lib/jvm/java-6-sun/jre
You should see a file cacerts in this directory. Next run:
keytool -import -alias your.host.com-1 -file my_actual_cert.cer -keystore cacerts -storepass changeit

This will effectively add the certificate you just exported to the trusted certificates.

Making Glassfish trust our certificates

To do this, you need to point to the trustStore you just updated (cacerts) in the properties associated to the Glassfish JVM.
First of all copy the cacerts keystore file you just updated to <your_glassfish_domain>/config/my-cacerts.jks

Next login to the Glassfish Admin Console, and proceed to
Common Tasks -> Configuration -> JVM Settings -> JVM Options

Change the property
-Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/cacerts.jks

to
-Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/my-cacerts.jks
Save your changes and restart glassfish.

Making WebSphere Application Server trust our certificate

is documented here (among other places no doubt); basically the same steps.

Sending mail

Check out one of many samples available online showing how to send email using Spring facilities. This is a quick and dirty example without injection.

<bean id="mailSender" p:port="your_port" p:host="your.host.com" p:username="your_authenticating_user" p:password="your_pwd" p:protocol="smtps">
    <property name="javaMailProperties">
      <props>
        <prop key="mail.smtps.auth">true</prop>
        <prop key="mail.smtp.starttls.enable">true</prop>
     </props>
    </property>
</bean>

Afterwards you can just inject the mailSender and use it as desired.

Note that you can easily inject a JNDI mail session, which I didn’t do because there’s no real advantage to warrant having to ensure the proper JNDI resource(s) exist on different servers in this case.

Happy sending! :-)

Is the Java Store dead ?

Friday, June 4th, 2010

I’ve been waiting since Devoxx for the Java Store to become available in Belgium.Seemingly zero changes since then :-(

Although it might not be the most original idea, it does sound like a natural fit for the java platform on the desktop.

Anyone knows if Oracle killed this off or if it died when James Gosling left Oracle ?

I for one am still rooting for this to actually happen. Yes I’m a dreamer.

Compiling Spring 3 from SVN on Linux

Wednesday, November 11th, 2009

Mostly so I don’t forget myself next time :-)

Don’t forget to checkout only the wanted HEAD revision from svn:

svn co -r HEAD https://src.springframework.org/svn/spring-framework/trunk spring-framework

If you have ant as part of your distro (as is the case in gentoo), download a binary ant distribution and run <your_new_ant_path>/bin/ant instead of the ‘default’ ant to prevent any classpath issues.

Make sure you do

export ANT_OPTS=”-XX:PermSize=128m -XX:MaxPermSize=128m”

If necessary add -Xmx512m or more too.

Enter build-spring-framework and run

<your_new_ant_path>/bin/ant

to build Spring. In order for Eclipse to be able to find all required jar’s, you’re probably best running the resolve ant target in most of the subprojects.

Open import the projects to an Eclipse workspace, set the IVY_CACHE classpath var in Eclipse prefs to spring-framework/ivy-cache

I had a few errors in tests for the oxm bundle failing, but since I don’t really need them anyways I just removed the src/test source dirs from the oxm project in Eclipse :-)

It’s 2 AM so yea, the above is probably pretty messy :)

Can’t find the Capabilities prefs pane or Classic Update?

Wednesday, December 17th, 2008

Eclipse 3.4 Ganymede introduces a new UI for software updates.

In order for the Help->Software Updates submenu to show up again:

  1. install the Eclipse SDK plugin if needed
  2. enable Classic Update in Preferences->General->Capabilities

Easy as eating … fries! :-)

64bit Flash plugin for Linux, finally!

Monday, November 17th, 2008

Pigs seem to be able to fly as Adobe today released a preview 64bit release of it’s Flash plugin!

Are the days of using nspluginwrapper finally over? I suppose we can’t expect too much of a preview but those days seem to be coming!

If now we get a fast 64bit native java runtime (with a working -client option please), I guess the productive life in the 64bit Linux world is finally no more painful than the 32bit world.

Kudos Adobe, this is a step in the right direction!

Now, please also create a Linux version equivalent (or even something better maybe) to Digital Editions and I can actually take advantage of my digital subscribtion to www.standaard.be to read the entire paper digitally.

The pain of setting the classpath through the Jar Manifest

Wednesday, October 8th, 2008

I’ll keep this short: jar manifests suck. I just found out a jar wasn’t loaded as it was supposed to because my manifest classpath entry was 70 chars long (including the first space!). All other lines were 71 chars long, except this one because the entry was finished, so I was missing one space.

Netbeans handles this nicely when I build my app consisting of a number of projects with jar dependencies. Everything ends up ready to run in the dist dir of the main project root. Neat and simple. In Eclipse I seem to overlook the ability to export a Jar with it’s dependencies’ classpath preconfigured & packaged alongside the project code. I mean, am I *supposed* to do this myself?

I guess I really need to upgrade to using ant or maven and automate these kinds of things … and I will! Euhm … soon!

Since this is a clientside project, I’ll finally make the step and get the right kind of certificate to sign my code and WebStart enable the entire thing. And unless I solve these issues, I’ll return to netbeans for that purpose, although MyEclipse finally enabled me to stick with Eclipse :(

Until I switch to something automated of course :-)

Tired now. Need sleep.

Nite nite.

PS: I was about to reread but I’m too tired, so sorry, it’s probably badly written and ill-structured (or something)

‘Fixing’ the slow JFileChooser on Windows XP

Friday, September 26th, 2008

Ever used a Java Swing app on Windows XP that seemed to freeze when you open a JFileChooser dialog? Apparently it’s caused by calls being made to Windows’ infamous integrated ‘compressed folders’ utility when files are recognized as archives.

The bad news is that every stable Sun JVM on Windows XP up to today suffers from this issue.
The good news that the issue has been f fixed in Java 1.6u10b07. Although I don’t presume to know the entire history of this bug, it seems a little sad to see this one was reported against release 1.4.2.

To fix on java versions predating 6u10b7, the only fix is effectively unregistering the zip folder dll from windows. Since I won’t quite use 6u10 until it’s GA and I’ve been a happy 7zip user on every OS I use for quite some time now I decided to go for the uninstall.

To unregister (and disable ‘Compressed Folders’):
regsvr32 /u %windir%\system32\zipfldr.dll

If you decide for some reason you can’t live without it and want to re-enable, execute again from a cmd :
regsvr32 zipfldr.dll

and you’ll be sending things to compressed folders before you know it :-)

GPL’d Java vs. Gosling Emacs

Monday, June 23rd, 2008

A nice comment on a slashdot story reporting on made advances in opening up Java taught me a few nice trivias on the history between Richard Stallman and James Gosling in the early days:

“In the early years (1984 to 1988), the GNU Project did not have a single license to cover all its software. What led Stallman to the creation of this copyleft license was his experience with James Gosling, creator of NeWs and the Java programming language, and UniPress, over Emacs. While Stallman created the first Emacs in 1975, Gosling wrote the first C-based Emacs (Gosling Emacs) running on Unix in 1982. Gosling initally allowed free distribution of the Gosling Emacs source code, which Stallman used in early 1985 in the first version (15.34) of GNU Emacs. Gosling later sold rights to Gosling Emacs to UniPress, and Gosling Emacs became UniPress Emacs. UniPress threatened Stallman to stop distributing the Gosling source code, and Stallman was forced to comply. He later replace these parts with his own code. (Emacs version 16.56). (See the Emacs Timeline) To prevent free code from being proprietarized in this manner in the future, Stallman invented the GPL.”

Nice to see how (as the comment author puts it) ‘Richard was right.’

The rest of the comment ( & story) is equally worth a read. Long live the GPL & Java! & so many others :)

JDK 6u10 early access features Nimbus Look ‘n Feel

Monday, April 7th, 2008

Although I found the Ocean look to be a major improvement of the Metal look and feel (L&F), Nimbus seems a big step forward once again. And not an unwelcome one at that.

It does deserve to be said that a project with a Swing frontend I’ve been working on for a client for sometime now has been running Ocean as default look for a while now. It’s primary user group are users with no technical expertise whatsoever, and after I disabled the native theme for a while to do some Vista testing and forgot to re-enable it later for the next release build, they’ve specifically asked me to switch back to Ocean afterwards when I had ‘corrected’ the issue. I still need to ask whether that was due to use of colors, font, dpi or messy Swing native theming.

Which brings up a question that crossed my mind a few times; how many or few colors can/should a business app gui use in it’s UI, before it gets that screaming feeling or transforms to the written equivalent of The Box Factory?

Since I try to adhere to splitting the layers and reusing components (sort of), the use of color seems pretty important when designing editors and viewers of different sorts. I suppose it should all be abstracted out to the presentation model right :-)