Blog Archives

Eclipse, Windows and Subversion

Yesterday I had to use Windows with Eclipse and I needed access to our Subversion repository. But we use SSH with certificates and I had a lot of trouble to get a working system. At the end I have installed TortoiseSVN and PLink to test the access.

First use PLink and check the access to your Subversion server. The certificate can reside within a running PageAnt or you can set the local path to your private key direct in the command-line.


"c:\program files\plink.exe" -2 -P <port> -noagent -i "H:\\keys\\subversion.ppk" user@server

This should create a connection to the user account on the Subversion server. You have to set double backslashes within the key parameter, because PLink is a Unix program, which uses backslash as escape character for the following character.

An alternative will be:

"c:\program files\plink.exe" -2 -P <port> user@server

if you use PageAnt and your certificate is imported there (you should look twice!). If you have a working connection, you can close it and now open TortoiseSVN->Settings. You will find a button, which lets you open the configuration file for Subversion.

TortoiseSVN settings

TortoiseSVN settings

In the configuration file define your own [tunnel] entry, which you can use as protocol extension. In example, you define a [tunnel] named as “work”, you can access the repository with:


svn+work://user@server/repository-path

Open the configuration file and scroll down to the [tunnels] sections. Now you can define:


work = "C:\\Program Files\\PLink.exe" -v -2 -P <port> -i "H:\\keys\\subversion.ppk" -noagent

You have to use double backslashes also for the program path to PLink, because TortoiseSVN uses also the UNIX notation. Now You can test the [tunnel] with your TortoiseSVN installation. Open your repository browser and enter the Subversion Uri as described above. Some command windows will be open, this is a side effect of PLink. If you can see the repository tree, we should test it without the explicit key notation and work with PageAnt.


work = "C:\\Program Files\\PLink.exe" -v -2 -P <port>

If the [tunnel] works again (PageAnt should run and the key should be imported), we replace the PLink with the TortoiseSVN internal variant, which is called TortoisePLink. This program doesn’t open a command window.


work = "C:\\Program Files\\TortoiseSVN\\bin\\TortoisePLink.exe" -v -2 -P <port>

Test it again with the repository browser. If all works fine, we can now open Eclipse to configure a repository there. I have installed Subclipse and JavaHL as connector. Go to Window->Preferences->Team->SVN and you can see the client “JavaHL (JNI)” with a specific version number. I’m not sure, whether or not Eclipse loads the Subversion config file from the Tortoise installation as default. So I have changed the location to the config file, which we have modified above. Normally you can find it within “C:\Documents and Settings\\Application Data\Subversion”. Check the content of the config file there, it should contain your [tunnel] definition.

Back to Eclipse, save the settings and open the Subversion perspective. Add a new repository and use the Uri:


svn+work://user@server/repository-path

That’s all.

Code Formatter Eclipse PDT

You can download a cool extension from http://sourceforge.jp/users/atlanto/pf/eclipse/files/ which allows you to define the code format for your PHP code. Install the .zip-file as archive with Eclipse’s “Install New Software…” feature.

Find all used IP adresses within a subnet

If your local computers allow a ping, you can simply execute:


nmap -sP 192.168.x.*

where x is the subnet number (1 <= x <= 254). You will get a list of all hosts, their IP addresses and their MAC addresses. That is really cool for DHCP networks, where you don't know, which IP addresses are already been used.

Log file of the Eclipse workspace

All errors are logged within


${WORKSPACE}/.metadata/.log

Here you can see ClassNotFoundExceptions and timeouts of I/O operations (like Maven index download).

Set the localtime on a Linux system

cd /etc

Set the timezone of your server location:

ln -sf /usr/share/zoneinfo/Europe/Berlin localtime

Check the new settings with:

date

If you have set the hardware clock with an UTC timestamp, the date command will calculate the correct time offset using the localtime settings (including daylight save time switch).

Access private fields per Reflections within Glassfish

You can not access a private field per Reflections, if your application runs on Glassfish. You have to set a policy entry on the server to permit it:

1. open the security policy file: glassfishv3/glassfish/domains/domain1/config/server.policy
2. include the following entry:

        grant codeBase "file:${com.sun.aas.installRoot}/domains/domain1/applications/arena-dwr/-" {
            permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
        };

Don’t forget to replace the arena-dwr by the name of your application, and also to check project path if you are not using the default container instance domain1.

Then you can call:

   Entity.class.getDeclaredFields()

without a SecurityException.

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