Running Ubuntu Linux on Acer Veriton X270

I recently brought an Acer Veriton X270.

Ubuntu Linux 8.04 works well except for sound. Basic stereo sound output works, but sound input (microphone) and some advanced 3D and surround sound does not work. The front headphone jack does not work correctly either. (All this works in Windows, so it’s not a hardware problem.)

Apart from the poor sound support in Linux, I am quite happy with this computer. It’s small (though not super small like Mac Mini or Fujitsu ESPRIMO Q), quiet, has all features you need and works out of the box. And it has a compelling price.

An odd detail is that it has HDMI instead of DVI for digital video output (it has VGA too, but who wants to use that nowadays?). But with a cheap HDMI-DVI adapter, you can connect a regular DVI display.

Posted in hardware, Linux | 2 Comments

Type safe JSP and JSTL

When using JavaServer Pages, you want to use JSTL to be able to to flow-control (iterations and conditionals) in a reasonable way. And the recommended way to use JSTL is to use the Expression Language (EL).

However, using EL is not a good idea at all. Contrary to Java and plain JSP, EL lacks static typing. This means that many errors which the compiler can catch is not detected until runtime when using EL. And even worse, EL doesn’t even do proper type checking at runtime. In many cases you just end up with an empty string when it in fact is a type error.

Proponents of dynamic languages usually say that static typing is not necessary since you should have automated testing of your code anyway, and that will catch any errors. However, automated testing of web pages is difficult and awkward. And reasonable dynamic languages (such as Python and Ruby) at least do type checking at runtime and generate a visible runtime error.

Fortunately, there is a feature of JSTL called rtexpvalue which makes it possible to use JSTL without EL and keep the static typing.

First you have to use alternative versions of the JSTL tag libraries:

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/xml_rt" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jstl/sql_rt" prefix="sql" %>

Then you use plain JSP expressions instead of EL:

<jsp:useBean scope="request" id="fuits" class="java.util.List"/>
<jsp:useBean scope="request" id="foo" class="com.acme.Foo"/>

<c:if test="<%= foo.isBar() %>">
	<p>Foo is bar since <fmt:formatDate type="time" value="<%= foo.getDate() %>"/></p>
</c:if>
<c:forEach items="<%= fruits %>" var="fruit">
	  <jsp:useBean id="fruit" class="com.acme.model.Fruit"/>
	      <tr>
	        <td><%= fruit.getColor() %></td>
	        <td><%= fruit.getTaste() %></td>
              </tr>
</c:forEach>

As you see, you have to declare the variables using <jsp:useBean>.

This makes the syntax a bit more clumsy, but that’s a price worth to pay to get the static typing.

To get the full benefit of the static typing, you should compile all your JSP pages offline before deploying the web application. The best way to do this is to integrate JSP compilation in your build process so that JSP pages is compiled at the same time as your regular Java code is compiled. If you use Maven, you can use this plugin.

Posted in Java, JavaEE, web | 1 Comment

java -classpath *.jar

It’s quite annoying that you cannot use wildcards in the -classpath command line option to java and javac. Quite often you want to include all .jar files in one directory.

Here is a way to get that effect:

java -classpath `echo lib/*.jar | sed -e “s/ /:/g”` org.foo.MyApp

You can even include all .jar files in a whole hierarchy of directories:

java -classpath `find repository -name *.jar -printf %p:` org.foo.MyApp

In general it’s better to use Ant or Maven for compiling and Java Service Wrapper for running, they have built-in support for wildcards. But they require some upfront setup, so my solution is useful for ad-hoc usage.

This works in Linux and probably in Solaris and other UNIX systems. If you use Windows, you need to install cygwin or similar.

Posted in Java | 1 Comment

Things you might want to change in Ubuntu 8.04 (hardy) desktop, part 2

After installing Ubuntu 8.04 (hardy) desktop, there are some things you might want to change. This article focus on user configuration (mostly editing dot files in your home directory) and do not require superuser access. Some of this changes requires that you log out to take effect.

Customize the bash shell

By default, bash save all commands in a history file. This can be quite annoying when you run several instances of the shell in parallel, and may also be a security concern. Add this line at the beginning of ~/.bashrc to only keep command in memory until you exit the shell:

unset HISTFILE
Customize the nano editor

Add this to ~/.nanorc:

unset backup
unset historylog
set nowrap
set quickblank
set tabsize 4
set morespace
Customize xterm

I prefer to use xterm instead of the default GNOME terminal. xterm does not look so good by default, by using this you can get it to look almost like GNOME terminal, but faster and with smaller memory footprint. Add this to ~/.Xresources:

XTerm*faceName: monospace
XTerm*faceSize: 10
XTerm*vt100.Background: white
XTerm*vt100.Foreground: black
XTerm*vt100.metaSendsEscape: true

xterm*saveLines: 1000
xterm*vt100.translations: #override \n\
                 <BtnUp>: select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0) \n

Then open “Perferred Applications” in “Preferences” in the System menu, open the “System” tab and select “Standard XTerminal”.

See also part 1.

Posted in Linux | 1 Comment

How to setup PPTP VPN in Linux

1. Create a file /etc/ppp/peers/name:

pty "pptp host --nolaunchpppd"
name username
remotename PPTP
require-mppe-128
file /etc/ppp/options.pptp
ipparam name

2. Add this line to the file /etc/ppp/chap-secrets:

username PPTP password *

3. Create a file /etc/ppp/ip-up.d/tunnel

#!/bin/sh

if [ "${PPP_IPPARAM}" = "name" ]; then
route add -net RemoteNetworkWithNetmask dev ${PPP_IFACE}
fi

RemoteNetworkWithNetmask is the network on the remote side you want to access via the VPN tunnel, e.g. 172.16.0.0/12.

Connect by running sudo pon name
Disconnect by running sudo poff
Check what happends by running plog

You can setup several VPN connections with different names, but I’m not sure if it’s possible to connect to more than one at the same time.

This is tested in Ubuntu desktop 8.04 (hardy) desktop.

Posted in Linux | 2 Comments

Things you might want to change in Ubuntu 8.04 (hardy) desktop, part 1

After installing Ubuntu 8.04 (hardy) desktop, there are some things you might want to change. This article focus on system configuration (mostly editing in /etc) and requires superuser access (using sudo). Some of this changes requires reboot to take effect.

Fix terminal font rendering bug

There is a bug which gives bad font rendering in the terminal window. Fix it by doing this in a terminal:

cd /etc/fonts/cond.d
sudo unlink 10-hinting-medium.conf
sudo ln -s ../conf.avail/10-hinting-full.conf
Fix bug in DHCP client

Fix a bug in the DHCP client described here.

Use GNU nano as default console text editor instead of vi

Add this line to /etc/profile:

export EDITOR=nano
Mount /tmp as tmpfs if you have plenty of RAM

Add this to /etc/init.d/mountkernfs.sh:

32a33,35
>       domount tmpfs "" /tmp -omode=1777,nodev,exec,nosuid
>       # this is necessary to avoid that files are removed later in the boot process
>       touch /tmp/.clean

And add this to /etc/init.d/mtab.sh:

100a101,101
>       domtab tmpfs /tmp "tmp" -omode=1777,nodev,exec,nosuid
Increase the limit of number of open files

Add this to /etc/security/limits.conf:

42a43,44
> *               hard    nofile          65536
> *               soft    nofile          65536
Setup some useful NTP servers and sync clock at each login

Setup some useful NTP servers in /etc/default/ntpdate.

Create a file /etc/X11/gdm/PostLogin/Default:

#!/bin/sh
#
# This script will be run before any setup is run on behalf of the user and is
# useful if you for example need to do some setup to create a home directory
# for the user or something like that.  $HOME, $LOGIN and such will all be
# set appropriately and this script is run as root.

ntpdate-debian -s
if [ $? -gt 0 ];
then
        logger -p user.err "ntpdate failed"
        zenity --warning --text "ntpdate failed"
else
        logger -p user.info "ntpdate successful"
fi

See also packages you might want to remove.

Posted in Linux | 2 Comments

How to use mousewheel in GNU Screen

GNU Screen has support for scrollback, but by default you have to use awkward keys to use it. I would like to be able to use Shift-PageUp, Shift-PageDown and the mousewheel to scroll, just like you can do in xterm.

It was not easy to configure Screen for this, and it involves cooperation with the terminal emulator. But I finally managed to achieve a solution which works pretty well. Add this to your ~/.Xresources file (you need to log out for this to take effect):

XTerm*saveLines: 0
XTerm*vt100.translations: #override \n\
  Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  Lock @Num_Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  @Num_Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  <Btn4Down>: string(0x1b) string("[5S") \n\
  Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  Lock @Num_Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  @Num_Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  <Btn5Down>: string(0x1b) string("[5T") \n\
  Shift <KeyPress> Prior: string(0x1b) string("[25S") \n\
  Shift <KeyPress> Next: string(0x1b) string("[25T") \n

Then add this to your ~/.screenrc file:

defscrollback 1000

# Scroll up
bindkey -d "^[[5S" eval copy "stuff 5\025"
bindkey -m "^[[5S" stuff 5\025

# Scroll down
bindkey -d "^[[5T" eval copy "stuff 5\004"
bindkey -m "^[[5T" stuff 5\004

# Scroll up more
bindkey -d "^[[25S" eval copy "stuff \025"
bindkey -m "^[[25S" stuff \025

# Scroll down more
bindkey -d "^[[25T" eval copy "stuff \004"
bindkey -m "^[[25T" stuff \004

This works in xterm. I’m not sure if it works in other terminal emulators.

Note that this disables the normal scrolling support in xterm, you will only be able to scroll when using Screen. You might want to start xterm like this to always use Screen:

xterm -e screen
Posted in Linux | 8 Comments

How to use Ctrl-Tab in GNU Screen

GNU Screen allows you to open several sub-windows within one terminal window. By default, you switch between them using Ctrl-A followed by n or p. I think this is a bit clumsy, I would like to switch with Ctrl-Tab and Ctrl-Shift-Tab just like you switch tabs in Firefox and many other applications. The sub-windows in Screen is conceptually just like tabs in Firefox, so it’s logical to use the same keys to switch between them.

Screen can be configured to use any key combination for switching sub-window by using the bindkey command. However, Screen can only recognize the key combinations that your terminal emulator actually intercept and send a unique code for. By default, most terminal emulators do not intercept Ctrl-Tab, they just send the same code as for Tab. And you certainly not want to use that since Tab is used for tab completion in the shell.

So you need to configure your terminal emulator to intercept and send a unique code for Ctrl-Tab. In xterm, you can do that by setting the X resource XTerm.vt100.modifyOtherKeys: 2. Now xterm sends ^[[27;5;9~ for Ctrl-Tab and ^[[27;6;9~ for Ctrl-Shift-Tab (^[ is ESC). However, you don’t want to use this since it mess up other things. You need to configure just Ctrl-Tab and Ctrl-Shift-Tab without altering any other keys. This can be done using the translation feature. Add this to your ~/.Xresources file (you need to log out for this to take effect):

*vt100.translations: #override \n\
        Ctrl ~Shift <Key>Tab: string(0x1b) string("[27;5;9~") \n \
        Ctrl Shift <Key>Tab: string(0x1b) string("[27;6;9~") \n

Then add this to your ~/.screenrc file:

# Ctrl-Tab
bindkey "^[[27;5;9~" next

# Ctrl-Shift-Tab
bindkey "^[[27;6;9~" prev

This works in xterm. I’m not sure if it works in other terminal emulators.

Posted in Linux | 2 Comments

Configure web applications in JBoss

When you deploy a web application in a JavaEE application server, it usually consist of a .war archive.

Sometimes, the web application needs some configuration parameters. The most common way to do this is to have <context-param> in web.xml. That is simple and works fine except that the web.xml file needs to be inside the .war archive. This makes it inconvenient to change a configuration parameter since you have to repack the .war archive. You also have to set the same value several times if several web applications share the same configuration.

It would be nice to be able to specify the configuration parameter values outside the .war archive, in a way so that several web applications in the same application server can use the same parameter value. Sadly, the JavaEE specification offers no simple way to do this portably.

However, I found a way to do it in JBoss 4.2.2. Create a file named something-service.xml in the JBoss deployment directory with the following structure:

<server>
<mbean code="org.jboss.naming.JNDIBindingServiceMgr"
       name="pm-urls:service=JNDIBindingServiceMgr">
    <attribute name="BindingsConfig" serialDataType="jbxb">
    <jndi:bindings
        xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
        xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd">
    <jndi:binding name="myapp/BackendHost"><jndi:value>somehost</jndi:value></jndi:binding>
    <jndi:binding name="myapp/BackendPort"><jndi:value type="java.lang.Integer">4711</jndi:value></jndi:binding>
    </jndi:bindings>
    </attribute>
    <depends>jboss:service=Naming</depends>
</mbean>
</server>

Then lookup the configuration parameters using JNDI in the web application(s):

    InitialContext initCtx = new InitialContext();
    String backendHost = (String)initCtx.lookup("myapp/BackendHost");
    int backendPort = (Integer)initCtx.lookup("myapp/BackendPort");

Se some documentation about this.

Posted in Java, JavaEE | 1 Comment

Packages you might want to remove from Ubuntu 8.04 (hardy) desktop

When you install Ubuntu 8.04 (hardy) desktop, you get a lot of packages installed by default. Most users will never use many of these packages, so you end up with a lot of unnecessary packages. Most of these packages are harmless and only waste disk space when not used.

However, some packages can actually affect the system in a negative way, such as draining resources (other then disk space), and you should consider removing them if you not actively use them.

To remove some of these packages, you also need to remove these metapackages:

ubuntu-desktop
ubuntu-standard
ubuntu-minimal

Tracker

Tracker indexes your files in the background. This can slow down your computer considerably.

libtracker-gtk0
tracker
tracker-search-tool
libdeskbar-tracker

Locate

Locate is another tool for indexing your files. It makes not much sense to have it in parallel with tracker.

mlocate

Avahi

Some multicast DNS stuff. Contains a network daemon, and good security common sense tell you to remove all network daemons you don’t actually use.

avahi-autoipd
avahi-daemon
libavahi-core5
libnss-mdns

Bluetooth stack

Quite useless if your computer doesn’t have Bluetooth.

bluez-audio
bluez-cups
bluez-gnome
bluez-utils

Network Manager

Can be good to have on a laptop with wireless networking. But makes no sense if you have a permanent wired network connection (or no network connection at all).

network-manager
network-manager-gnome
libnm-glib0
libnm-util0

Usplash

Display a pretty image during boot, hiding a lot of possibly interesting messages. Does not work with some display adapters.

usplash
usplash-theme-ubuntu
libusplash0

Evolution

A groupware suite, contains a daemon (evolution-alarm-notify).

evolution
evolution-common
evolution-exchange
evolution-plugins
evolution-webcal
contact-lookup-applet
libexchange-storage1.2-3

Vim

A text editor that some people finds very hard to use. Used by default by some commands such as visudo, so you might accidentally end up in a awkward text editor you don’t even know how to exit.

vim-common
vim-tiny
Posted in Linux | 5 Comments