Execute JerseyTest case within Eclipse

If you execute a test case within Eclipse, it is possible to fail already on the build of the WebDescriptor. You should add

-Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory

to your Debug/Run configuration to test against the deployed WAR on the Glassfish server, which runs within Eclipse. Normally the init process of the JerseyTest should find a factory class, if it is within the classpath. The pom.xml contains a dependency to something like

<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-external</artifactId>

which provides the ExternalTestContainerFactory. But Eclipse could not find it and got a NPE on startup of every test case.

GWT no longer supports Quirks Mode

To prevent that warning, you should add

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

to your “index.html”. The standard page for a GWT project in Eclipse doesn’t contain a DTD reference, so you should add “loose.dtd”. An alternative could be, that you add

<extend-configuration-property name="document.compatMode" value="BackCompat">

to your module XML file. But this only hides the warning and doesn’t solve the problem.

HTPP -> HTTP redirect on Glassfish 3.1.2.2

Execute this on your Glassfish machine:

###
### HttpToHttpsRedirectOnDifferentPort
###
asadmin create-protocol --securityenabled=false http-redirect
asadmin create-http-redirect --redirect-port 443 --secure-redirect true http-redirect
asadmin create-protocol --securityenabled=false http-redirect-base
asadmin create-protocol-finder --protocol http-redirect-base --target-protocol http-listener-2 --classname com.sun.grizzly.config.HttpProtocolFinder https-finder
asadmin create-protocol-finder --protocol http-redirect-base --target-protocol http-redirect --classname com.sun.grizzly.config.HttpProtocolFinder http-redirect
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=http-redirect-base

Finding a file containing a particular text string

To find a text within all files of a directory use the following command:

grep -H -r "needle" /hay/stack

Set date and time on a Linux command line

You can set date and time of a linux server with:

date +%Y%m%d -s "20131228"

which sets the date to the 28th of December in 2013.

date +%T -s "20:15:45"

which sets the time to a quarter past 8 PM (and 45 seconds).

If you set the system datetime, you can also set the hardware clock:

hwclock --systohc --localtime

Change Maven repository directory within Eclipse

If you use the embedded Maven installation within Eclipse, the default .m2 directory (which contains the repository) resides in the profile of the current user.

In Windows, this is the C:\Documents and Settings\<user> directory. A large repository there could result in problems with server based profiles. Is there a quota on the server, it could be not possible to save the profile back to the server, if it contains a lot of Maven artifacts.

You can set the repository directory within the settings.xml. Copy the .m2 directory into another path on your computer (outside of your profile). Edit the settings.xml and set a new path to your repository:

  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ~/.m2/repository -->
  <localRepository>C:/arothe/.m2/repository</localRepository>

Enter Eclipse Preferences and change the User Settings path. Click on “Update Settings” and the Local Repository should be changed to the path defined within your settings.xml. Click on “Reindex”.

Eclipse Maven Settings

Last but not least, delete the .m2 folder from your profile directory.

Change version for GWT application

In Eclipse are different places where you can change the version of your web application.

1. Your pom.xml
Change the version of your artifact like:

<groupId>de.uni_leipzig.smo</groupId>
<artifactId>trialregistry-gui</artifactId>
<version>0.3-SNAPSHOT</version>
<packaging>war</packaging>

2. Your build path
Set the default output folder to something similar to your pom.xml:

Build Path Settings

3. Your Run configuration
To run GWT applications you define a Run configration within Eclipse. The tab “Arguments” contains also a path to the war-directory, which could contain the version number:

Run Configration

Use a simple shell within Eclipse

The WickedShell project provides a shell view within Eclipse to execute some scripts or programs. It is very simple to execute a Maven build within this shell instead of opening a terminal window from the Linux desktop. Very cool!

http://www.wickedshell.net/

GWT Compile and wrong output dir

If your “GWT Compile” process exports the “deploy” directory to the wrong place, you can correct this within the preferences file com.google.gdt.eclipse.core.prefs, which you can find within the “.settings” directory of you Eclipse project.

eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
lastWarOutDir=/path-to-your-project/src/main/webapp
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

Change the “lastWarOutDir” to the correct path. It should contain the “WEB-INF” directory and GWT should create a “deploy” directory within it. Restart your IDE to load the new settings! You can check the results during “GWT Compile” with log level TRACE.

Auto adjust Grid

If you have a Grid within a Panel or Window class and the Grid will not be automatically adjusted, you will have to check the complete widget hierarchy for valid LayoutManagers. All parent widgets of the Grid must use the layout sytem. Then we can use

  grid.getView().setAutoFill(true);
  grid.getView().setForceFit(true);

The parent Panel or Window should define an minimal height and width.

  window.setLayout(new FitLayout());
  window.setMinWidth(500);
  window.setMinHeight(400);

Every resize operation on the Panel/Window should resize the Grid too. If you forget the layout on the window or its panels, the grid will not be displayed till you set a height and width explicitly.