OpenTTD 1.0.0 released!

On April 1st, OpenTTD released their version 1.0.0. It is the first official version that is fully usable without the original graphics, music and sounds through the optional installation of OpenGFX, OpenMSX, and OpenSFX. Luckily, the developers haven’t changed the implementation of the information gathering UDP packets and jOpenTTDLib is still compliant!

No Comments

jOpenTTDLib goes SourceForge!

I’ve finally migrated jOpenTTDLib to SourceForge. The project web page is still http://openttd.camelspotting.com but all files have been moved to SourceForge.   :mrgreen:

,

No Comments

Is it possible to list directories inside the Java classpath? (SOLVED!)

After writing on a piece of Java software for some weeks I came to the point where I wanted to enable Java Web Start deployment. I usually do this by enabling JWS on my NetBeans project and allow NB to do it’s thing. This works great and all that remains for me is to dump the files onto som web server.

When launching the program I notice that some GUI functions, which work as intended when running offline, suddenly refuse to work. The logs revealed the following exception.

java.lang.IllegalArgumentException: URI is not hierarchical

It turned out that I had a method where I treated a classpath URL like it was a normal URL. In Java, one normally retrieves a file thusly:

java.net.URL url = class.getResource("/package/subpackage/file.extension");
java.io.File file = new java.io.File(url.toURI());

This operation fails miserably when deploying through JWS, because when run through JWS the URI retrieved does not point to an actual file (that is, a file that can be treated as java.util.File). In my case I tried to list the content of a specific package to ascertain which locales were available through filename identification. If only I could have achieved this directory listing without creating a File-object!

EDIT:

With a little help from a friend and some experimentation I’ve solved the problem (I’ve excluded exception handling for clarity):

String url = Util.class.getResource("/package/that/is/contained/within/desired/jar/").toString();
url = url.substring(0, url.lastIndexOf("!/") + 2);
JarURLConnection conn = (JarURLConnection) new URL(url).openConnection();
Enumeration<JarEntry> enumeration = conn.getJarFile().entries();
while (enumeration.hasMoreElements()) {
    // Filename handling here
}

It is imperative to choose a package that lies within the jar you wish to investigate (or else the classloader will return the wrong jar-file). The enumeration will list every last file contained within the file.

No Comments

Apache Tomcat 6.0 integration with Apache 2.2

So, I spent the greater part of this Saturday on enabling Apache to pass on certain requests to my Apache Tomcat server. Firstly, this was done on FreeBSD 7.2, but I’ll try to keep this at a more generic level. And also I’ll keep it high level as this is not a HOW-TO for either web server.
The software we will be needing:

So, the gist of the thing is to configure the bridge between the two Apache’s so let’s get to it. Before you read on, I am aware that it is possible to let Tomcat generate the mod_jk.conf-file and I’ll get to that further down.

Apache Tomcat

The part of your Tomcat configuration in which we’re interested is in $TOMCAT_HOME/conf/server.xml. The service that you would like to connect to will need the following connector directive which is the actual entry point for Apache (I’ve also included a virtual host which we’ll match in the Apache config later):

<Connector port="8009" protocol="AJP/1.3" />

<Host name="openttd.camelspotting.com" appBase="/path/to/tomcat/webapps/openttd"
 unpackWARs="true" autoDeploy="true"
 xmlValidation="false" xmlNamespaceAware="false" />

Apache

First we will need a worker. Think of him as the one who’ll carry the requests across the bridge and return the responses. Create a file called worker.properties. You can put this file wherever you want but usually it’s practical to put it next to your httpd.conf file, i.e. $APACHE_HOME/worker.properties. Example content:

workers.tomcat_home=/usr/local/apache-tomcat6.0
workers.java_home=/usr/lib/diablo-jdk1.6.0
worker.list=default
worker.default.type=ajp13
worker.default.host=localhost
worker.default.port=8009

So here you see: I’ve used port 8009  (the default ajp13 port). This has to match the port in the connector described above. Also, notice that the worker is called default. For more details on this file, check out the official documentation. Next, notice that my servers are running on the same host; hence the localhost value for the host property.

All right, final bit of configuration now: create a file (usual name mod_jk.conf) and put it somewhere (usually alongside httpd.conf). Example content:

JkWorkersFile "/usr/local/etc/apache22/workers.properties"
JkLogFile "/var/log/httpd/mod_jk.log"

JkLogLevel emerg
<VirtualHost openttd.camelspotting.com>
    ServerName openttd.camelspotting.com
    JkMount /* default
</VirtualHost>

As you see, the first line defines the worker-file you created previously, so change this to your own setup if necessary. The important thing to notice, though, is the JkMount-directive. The second argument is ajp13 which, you’ll remember, is our worker. Now, add the following line to your httpd.conf:

Include /usr/local/etc/apache22/mod_jk.conf

As usual, modify this path to match your setup. Remember to verify that the jk module is loaded in httpd.conf. It usually looks something like this:

LoadModule jk_module          libexec/apache22/mod_jk.so

The final step is to check your httpd.conf syntax and load the new configuration in some way (start/restart/graceful).

Apache Tomcat mod_jk.conf automatic generation

Tomcat can be configured to generate mod_jk.conf automatically such as to avoid having to edit it every time you change something in Tomcat. This is done by including the following line inside the engine-tag inside your service-tag of server.xml.

<Listener className="org.apache.jk.config.ApacheConfig"
     modJk="/usr/local/libexec/apache22/mod_jk.so"
     workersConfig="/usr/local/etc/apache22/workers.properties" />

By now, these attributes should be self-explanatory. When Tomcat is started it proceeds to generate the mod_jk.conf-file automatically which can then be included into httpd.conf. Sounds great! Well, I could not get that to work at all. The problem is that the generated file does not include any JkMount /* default directives. Please, if someone could tell me what I’m doing wrong, I’ll be thoroughly grateful.

, , ,

No Comments

jOpenTTDLib

I’ve added a list of “Extremely useful links” to the sidebar. The only entry, for now, is a link to my pet open source project.

My first, personal, open source project is… well, I’ll just quote myself:

The project jumpstarted when one of the authors had a severe procrastination attack during the exam period of December 2007. The result is something everyone can enjoy: live stats from your favourite OpenTTD server! And that, our friends, is awesome!

To discover exactly what it can do, please visit http://openttd.camelspotting.com!

,

No Comments