Get current JTA transaction status from CMT EJB

You probably know that if you use BMT (Bean Managed Transactions) you can get information about current transaction status by using UserTransaction interface (which implementation can be fetched either by JNDI or using dependency injection) and executing it’s getStatus() method. If you use CMT (Container Managed Transactions) you cannot use UserTransaction interface. Instead, you can manage your transaction through SessionContext interface. This interface gives you two places that hooks to the current transaction: setRollbackOnly(-) and getRollbackOnly()....

September 1, 2011 · 1 min

Screw Eclipse... and packages... and IDE... no, wait... screw me!

Just a note to myself – always check what classes are you importing in IDE, because if you see @Singleton in your class, it doesn’t mean it will work as a EJB Singleton. In my case it wasn’t referencing to javax.ejb.Singleton as I assumed, but com.sun.jersey.spi.resource.Singleton. Wasted 2 hours of looking for the answer or issue in a glassfish-3.1 JIRA. Did I mention I should always check the exact package of the imported class…?...

August 31, 2011 · 1 min

Why my hosts file doesn't work in Windows?

Once again Windows know exactly how to surprise me. I’ve added entries to the Windows/System32/drivers/etc/hosts on my remote Windows 2008 Server. The entry was resolved properly as it could be tested from the command line (ping, telnet, etc.) but in IE and FF browsers it didn’t work. DNS flushing, clearing browsers data or restart didn’t help a bit. It occurs that the IE had a proxy settings and apparently (when any proxy is set) it refuses to take hosts file under consideration....

August 31, 2011 · 1 min

How to find out what GNU/Linux distribution you're using

Recently I needed to find out what GNU/Linux a terminal-only server is using. The most obvious thing I could think of was to use: uname -a Unfortunately, it will return the kernel information only – no details about the distribution though. The distribution info is located in a different file which is dependent on… the distribution itself. Check out the list of those filenames here. As a majority of those files ends with “release” part, in most cases it should be enough to execute the following command:...

August 19, 2011 · 1 min

Running GUI applications over SSH

If you want to execute a GUI based application on the remote server through SSH, you can achieve it quite easily using the ssh command. Just type ssh -X username@server The -X flag is used to define the DISPLAY environmental variable on the remote host, so each X11 executed application will be forwarded to your machine.

August 19, 2011 · 1 min

Arquillian, ShrinkWrap and archive filename

When you create a deployment using Arquillian (great test runner for testing your Java EE code in the container of your choice: jBoss, Glassfish, OpenEJB, … either in embedded, managed or remote mode) remember that the name of the deployment archive file is the exact filename that will be executed in the container. It does make a difference if you use *.war or *.jar for your deployment, so beware the following construct if it’s not exactly what you intended to do:...

June 13, 2011 · 1 min

ShrinkWrap -- adding classes to non-root location

If you want to add your classes (or any other resources) to your ShrinkWrap archive to a non-root location, you can use the following: @Deployment public static JavaArchive deploy() { // This is the classes and resources archive JavaArchive ar; ar = ShrinkWrap.create(JavaArchive.class, "resources.jar") .addPackage(TestClass.class.getPackage()); /* * The 'ar' archive will be added to the 'yourDir', so you'll * end with test.jar#/yourDir/TestClassPackage/TestClass.class */ JavaArchive endArch; endArch = ShrinkWrap.create(JavaArchive.class, "test.jar") .merge(ar, "yourDir"); endArch....

June 13, 2011 · 1 min

Java classpath and wildcards

Pretty useful thing about the Java classpath definition is that the wildcard (*) can be used in a replacement of all *.jar and *.JAR files in the specified directory. So the following line: java -cp /tmp/app/*:/tmp/myJar.jar com.nullhaus.MyApp will add the /tmp/myJar.jar to the classpath, as well as all the *.jar and *.JAR files in the /tmp/app directory. Just remember that classpath never works recursively, so if you want to scan a subdirectory for jars you need to point it explicitly....

May 19, 2011 · 1 min

Properties -- be aware the evil whitespaces!

Just a letter to my future self: When you use Properties and creates the entries, remember to avoid the whitespaces. The properties are inserted as-they-are, so no trimming occurs. It might sound trivial, but it wasted at least an hour of my time, while I was searching for a bug in a totally wrong department… Pure evil: Properties p = new Properties; p.put("java.naming.factory.initial", " org.apache.openejb.client.LocalInitialContextFactory");

May 19, 2011 · 1 min

More than one -exec in find

I was trying to execute several commands on a single record found by the GNU/Linux find command. The first attempt was to create something like: find . -name "*.pdf" -exec echo 'test' && echo 'test2' \; But it’s not the way the find command works. If you want to execute more than one command for each hit, you should use multiple -exec actions: find . -name "*.pdf" -exec echo 'test' \; -exec echo 'test2' \; I used this feature to list JAR files in a specified location along with classes they consist of:...

April 24, 2011 · 1 min