Java Application Porting from Windows to Linux

We ported an old, and rather unusual Java application to Linux. Java is supposed to be platform independent, so this should be easy. But this is not your typical Java application. Here are the things we had to change to make it run in Linux.

Database Migration

The old Java application was using Microsoft Access as the database. The plan is to move it over to MySQL. The first step is to export the data, and we followed the MySQL documentation on how to export from Microsoft Access.

We then had to alter the exported tables since the primary keys were not auto incrementing.

<pre>alter table TABLE_NAME change column ID ID int auto_increment primary key;</pre>

We also hit a snag with MySQL in Linux case sensitivity, so we had to rename our tables, and explicitly made them capitalized.

<pre>rename table table_name to TABLE_NAME;</pre>

In the code, we had to use the MySQL driver com.mysql.jdbc.Driver, instead of the ODBC driver sun.jdbc.odbc.JdbcOdbcDriver. We also had to change SQL dates, so they are enclosed in single quotes (‘), instead of hash (#). So the dates in SQL should look something like ‘2013-09-01 01:00:00’ instead of #2013-09-01 01:00:00#.

Excel Import

The application was importing data from either XLS files or CSV files. The XLS import was implemented using ODBC, specifically using the Excel ODBC driver jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)}”. To make this work in Linux, the code was rewritten to use Apache POI HSFF/XSSF.

Runtime.exec() of .EXE

The application was running .exe files by using Runtime.exec(). We determined it was not an important functionality, so the code has been removed.

Ports 25, 53, 80, 110, 389

The application was running HTTP, DNS, LDAP, POP, and SMTP services, and were using the standard ports. These ports were below 1024 so they require root privileges. We don’t want the application to run as root, so we had to do something. Since we are in Linux, we could easily use the built-in DNS, LDAP, POP and SMTP services and thus, disabled these on the application. For port 80, we changed the application to run on port 8080 instead, and will put Apache in front to listen on port 80 once we are ready to move this to production.

Swing

The application had both a Swing interface and a Web interface. Since we are running on a headless Linux server, we were getting java.awt.HeadlessException. Functionality on the Swing interface where moved to the Web interface and the Swing code was disabled.

Permission

The application was running fine on Windows but on Linux, it was failing where it was creating directories and writing files. Because of the more secure nature of Linux, we needed to make sure that the application has permissions to the directories it was writing to. We also had to move some directories within the application directory itself, so we can easily set and keep track of the permissions.

Case Sensitivity

Files in Linux are case sensitive. Windows does is case insensitive. We had to hunt down filename references used by the code and in web pages. The application was trying to read files that had a lowercase extension but the filename in file system is all uppercase. The same goes for image references in web pages, like looking for IMAGE.GIF but the actual file is image.gif.

/ vs \

The last thing we had issues with was the use of \ in the Java code. We just had to find these using a global search and replace them with /, which works on both Windows and Linux.

Windows

After these changes, we were able to run this on a Linux box. We were debugging this on Linux the whole time, so we first ported this on Ubuntu Desktop. The nice thing about this porting project is that our Java application is now truly ported, and can now work on Windows, Linux or the Mac.

Posted in Technology.

Leave a Reply

Your email address will not be published. Required fields are marked *