Sunday, September 9, 2012

A trick to help with the Eclipse update blues

I think anyone who uses Eclipse has cussed at the software installer/updater/marketplace.  Tonight I tried to install the eGit plugin from the marketplace with no luck.  As usual, every time it tried to download something from download.eclipse.org, usually content.jar, it would hang until the 600s network timeout elapsed.

I did a little googling and stumbled upon a JVM setting that fixed the problem in this instance.  Crack open the eclipse.ini and throw this parameter into the -vmargs:

-Djava.net.preferIPv4Stack=true

After doing that the updates worked great.  All the network communication went by quickly on my cable modem and I wasn't sitting there wondering what the hell Eclipse is doing.  I can live with slow downloads when I can see progress going by but the 10 minute hangs with no feedback...

For what it's worth, the other trick I saw that people found helpful was to go to the 'Install New Software' screen and uncheck the 'Contact all update sites during install to find required software' check box.  That didn't help my issue, the JVM parameter is what did the trick there, but it's worth keeping in mind if updates are mis-behaving.

Any who, maybe this will help someone else out with Eclipse downloads.

Thursday, September 6, 2012

Using OpenMQ in Websphere (cliffnotes)

I couldn't find anything on using an OpenMQ message broker with the Websphere Application Server so here are the steps I followed.

Get the software
Download the developer edition of WebSphere
http://www.ibm.com/developerworks/downloads/ws/wasdevelopers/

* NOTE: on Ubuntu, replace the /bin/sh symlink that points to /bin/dash with a symlink that points to /bin/bash.  Otherwise the install will hang half-way through

Download the JavaEE SDK (probably called Glassfish) from Oracle

Setup OpenMQ
Start the imqbrokerd (the actual OpenMQ server)

Start the imqadmin tool, set up a queue, JNDI connection factory and destination.  This tutorial helps explain what to do:
http://docs.oracle.com/cd/E19909-01/817-3727/tutorial.html

Use this sample code to create a tester to make sure you have your queues all set up correctly:
http://www.java2s.com/Code/Java/J2EE/ThisexampleisasimpleJMSclientapplication.htm

Set up WAS
1. Create a new Generic JMS provider
Add these jars to the Classpath for the provider:

${glassfish3}/mq/lib/fscontext.jar
${glassfish3}/mq/lib/imq.jar
${glassfish3}/mq/lib/jms.jar
${glassfish3}/glassfish/modules/glassfish-naming.jar

Where ${glassfish3} is a variable that points to the glassfish3 directory on your system

If you forget one of these jars, werid werid werid exceptions occur that are hard to trouble shoot (catch them and print them to stdout when debugging)

External initial context factory:
com.sun.jndi.fscontext.RefFSContextFactory

External provider URL:
file:///tmp/OpenMQ

This should match the path used for the java.naming.provider.url in the OpenMQ object store

2. Create a Queue Connection factory

Name: lable is free form

JNDI name:
the JNDI name used by apps running in WAS, so this is the name WAS exposes for the resource

External JNDI name:
The JNDI name used in the OpenMQ object store for the ConnectionFactory resource which is listed under the "Lookup Name" column in the imqadmin tool

3. Create a Queue
Same instructions as the connection factory basically, only this time use the Destination in the OpenMQ object store instead of ConnectionFactory

And thats it!  If you're getting weird class cast execption or cannot connect exceptions, double check that all 4 jars are included AND that he external JNDI names matching.

WAS is terrible with it's Generic JMS exceptions. One trick is to catch and System.out.println the exception thrown when trying to pull the resource from JNDI or connect to the broker.  I found that this revealed more helpful exceptions that are not logged by WAS when the error occurs.

Sunday, February 5, 2012

Git, Eclipse and Maven multi-module project

More adventures in maven (sometimes I wonder how worth it is with maven), git and Eclipse...

So I have a multi-module maven project I'm working on, something of prototype to use for future reference for Maven managed EAR projects, and I'm using git for version control. I'm used to using SVN in Eclipse (via Subclipse) and CVS of course, unfortunately, but git's a little different. After some experimentation I think I've got things setup so that

A) the parent and each of the sub projects are connected to the same working git repo within Eclipse and
B) the Eclipse project settings are all managed by maven & the m2e plugins so that none of the Eclipse files (or dependency jars! ;) are checked into source control.

No real need there on that second point, just a preference since maven is so uber magically cool (</sarcasm>) and it handles all the gnarlly Eclipse project set up for you. If you like using other editors, this way you don't have all the Eclipse trash to deal with when you check the project out. Plus I like to hurt myself sometimes proving maven can do it a couple of times a year. Usually after a weekend, like this one, I have things worked out and it is actually pretty cool.
So when it comes to version control, to get everything set up and working using git I am doing the following:

  • Clone the project into my active workspace, either by command line or via the Eclipse egit wizards.
  • Import the existing maven projects into my workspace
  • Connect each of the imported projects to the git repo I'm working out it by right clicking on the project and choosing Team > Share Project > selecting Git then finally checking the "Use or create repository in the parent folder" check box. This can be done in bulk by selecting multiple projects

  • Now I have my nice snazzy maven/m2e managed multi-module project and all the flexible goodnes that comes with it, at least twice as much as needed to hang my self multiple times a day for a year, connected to git so I can check things in locally and forget to push the changes up to the bare repo I cloned from ; ) Good times.

    WAS command line to install an .ear

    This is a one liner that I just got to work which installs an .ear containing a single .war into my local copy of WAS8. It's only one example of how one could use the wsadmin command line tool to perform automated installations in WAS. Obviously different types of apps and configurations will require different command lines but this should get an interested person headed down the right road:

    ~/development/tools/IBM/WebSphere/AppServer/bin/wsadmin.sh -username admin -password admin -c '$AdminApp uninstall MavenTutEAR' -c '$AdminApp install MavenTutEAR-1.0.ear { -defaultbinding.virtual.host default_host -usedefaultbindings}' -c '$AdminConfig save' -c 'set appManager [$AdminControl queryNames type=ApplicationManager,*]' -c '$AdminControl invoke $appManager startApplication MavenTutEAR'

    Note that this is hardly the only, or the best way to do something like this. It is just A way to achieve what I was trying to do. Another option I was about to explore is trying out the auto deploy directory setup (Applications > Global deployment settings).

    If your actually curious why I'm doing this (much less posting about it) I have been trying to conquer my fear/ignorance of using maven with WebSphere, EAR's and possibly some EJBs... naa fuck that for now... by building a collection of maven projects that spit out an EAR that I can deploy into WAS. This monster command line is the finishing touch on that adventure.

    It's certainly not good for anything beyond local development, perhaps, but that's all I need right now. If I'm lucky, and the planets align, this same EAR project could be deployed into WebLogic or JBoss too with out much extra fuss.

    Anywho, many thanks to whomever put this page together:
    http://code.google.com/p/codesnippetssite/wiki/BasicWebSphereAdminwsadmin, it was a big help!

    Saturday, January 28, 2012

    WebSphere on Ubunu

    As I discovered trying to install the free version of WebSphere for developers (check it out here) Ubuntu uses the dash shell as its default instead of bash. I never noticed until I tried to use the WebSphere installer and it just hung forever for no good reason.

    Fortunately someone else had the same problem, figured out and posted it on their blog. Just change the symlink to point to bash instead of dash and the the WebSphere install works just fine. Here's the blog post I am talking about:

    http://www.pingudownunder.com/2009/09/10/getting-websphere-application-7-installed-on-ubuntu-9-04/