Friday, 12 September 2014

Moving From Ant to Maven

My project "karchangame" is Ant-based, basically because when you create a new project in Netbeans, the Ant configuration is the default.

This has worked well for a long time, until I decided recently to upgrade some of the libraries that I use. Now, in Ant, you just download the libraries you need and put the jar-files in your classpath.

That works fine if your libraries are not complicated. But I noticed that some of my libraries are now dependant on yet other libraries.

In short, I just spent an hour in getting the libraries I need, then getting the required libraries of those libraries, ad infinitum.

Maven takes care of this whole slog, by putting the responsibility for defining the required libraries for a framework/library squarely on the shoulders of that framework/library.

What I was stuck with was finding the best way of changing my Ant-based project into a Maven-based project.

Moving from Ant to Maven


The easiest way that I could come up with is to create a brand new Maven-based project. The original was a Web Application, so the new Maven project should also be a Web Application. As far as I could tell every possibility for a new ant-based project is also available as a new maven-based project.

And then start moving files over to the appropriate place in the new Maven structure.

I really like the fact that Git actually detects these moves instead of like in the old days, when a move was an explicit delete and create of two non-related files, making you lose your entire history of that file.

The difference in the directory structure is as follows:
You do notice that Maven actually has a more layered structure, whereas Netbeans Ant basically dumps everything in the root.

So, the move basically entailed the following:
From antTo Maven
build.xmlpom.xml
-nb-configuration.xml
nbproject-
lib- (actually stored in your m2 repo)
src/confsrc/main/resources
src/javasrc/main/java
websrc/main/webapp
testsrc/test/java
buildtarget
dist/karchangame.wartarget/karchangame-1.0-SNAPSHOT.war

Pom.xml

I only needed to make a few changes to my pom.xml file, in order to get all the dependencies sorted out.

JMockit

Needed to add JMockit, or my testcode didn't compile.
<dependency>

    <groupId>org.jmockit</groupId>
    <artifactId>jmockit</artifactId>
    <version>1.10</version>
    <scope>test</scope>
</dependency>

AntiSamy

AntiSamy to prevent evil hackers from gaining access.
<dependency>
    <groupId>org.owasp.antisamy</groupId>
    <artifactId>antisamy</artifactId>
    <version>1.5.3</version>
</dependency>

URL Validation

<dependency>

    <groupId>commons-validator</groupId>
    <artifactId>commons-validator</artifactId>
    <version>1.4.0</version>
</dependency>
It's amazing to see Maven automatically download all the required libraries.

The last part was adding plantuml back into the mix. But I'll talk about that in the next Blog.

References

Apache Maven
http://maven.apache.org/
Netbeans - MavenBestPractices
http://wiki.netbeans.org/MavenBestPractices

Friday, 5 September 2014

Welcome Banners in Linux

Seriously, there are more ways to create a Welcome Banner in Linux than there are to skin a cat.

As a matter of fact, only one of several ways will work on your system. It depends on what kind of system you have.

In my case I wished to automate the process, by referring to a file instead of having to type a new logon banner message every time.

Redhat Enterprise Linux 5

Change your custom.conf1, presumably it can be found somewhere in /etc/gdm/.

Redhat Enterprise Linux 6/Ubuntu 12

The new way2 4, using gconftool-2 to set appropriate key-value pairs.
gconftool-2 --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults --type bool -s /apps/gdm/simple-greeter/banner_message_enable true
gconftool-2 --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults --type string -s /apps/gdm/simple-greeter/banner_message_text "Your-Login-Banner"
gconftool-2 --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults --type string -s /apps/gdm/simple-greeter/banner_message_text "$(cat /opt/tools/info/message_of_the_day)"
gconftool-2 --config-source=xml:readonly:/etc/gconf/gconf.xml.defaults --get /apps/gdm/simple-greeter/banner_message_text

To effect this globally, we'll need to change it in a gconf database. The database used are dependent on who is logged on, but we don't want that.

The file /etc/gconf/2/path will show in which paths the database is consulted. The paths are in order of precedence. This means if an entry is found in one of the first databases, the entry is ignored in one of the latter databases.

By default there is a Mandatory Source, a User Source and a Defaults Source5. They are:
  • xml:readonly:/etc/gconf/gconf.xml.mandatory
  • xml:readwrite:$(HOME)/.gconf
  • xml:readonly:/etc/gconf/gconf.xml.defaults

If you wish you can set the logon message manually, using the gconf-editor tool. If you start it up as root, you will be able to select under "File" different profiles, namely the "Defaults" one and the "Mandatory" one.

Redhat Enterprise Linux 7

The new new way! People are migrating from GConf (gconftool-2, gconf-editor) over to GSettings3 and dconf (dconf-tool, dconf-editor).

Fedora 20

The workaround for Fedora, because the new new way doesn't work6.

Create file /etc/dconf/db/gdm.d/01-mysettings:
[org/gnome/login-screen]
banner-message-enable=true
banner-message-text='hostname: wiggins\n“How often have I said to you that when you have eliminated the impossible,\n whatever remains, however improbable, must be the truth?”\n\n- Sherlock Holmes, The Sign of the Four (1890)'
Don't forget to run, to recreate the database with the new settings:
rm /etc/dconf/db/gdm
dconf update

References

[1] Linux: Display a login banner gfor Gnome (GDM) manager
http://www.cyberciti.biz/tips/howto-unix-linux-change-gnome-login-banner.html
[2] RHEL6: Login Banners | SecureOS
http://secureos.wordpress.com/2011/07/21/rhel6-login-banner/
Wikipedia - GConf
http://en.wikipedia.org/wiki/GConf
[3] Chapter 3. GSettings and dconf
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Desktop_Migration_and_Administration_Guide/gsettings-dconf.html
[4] GConf configuration system
https://projects.gnome.org/gconf/
[5] Redhat - Introduction GConfiguration Overview
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Desktop_Deployment_Guide/ch-intro-gconf-overview.html
[6] Ask Fedora - How do I disable user list in gdm?
https://ask.fedoraproject.org/en/question/9875/how-do-i-disable-user-list-in-gdm/