Monthly Archives: August 2010

[How To] Convert a Maven Project to Eclipse Web Project

Eclipse WTP has this nice feature where it allows you to deploy, run and debug Web Applications from the IDE. You start by going to the Server View, adding the target server (like Apache Tomcat in our case) and then adding the Web Project to the server. This is how the view looks like:

addremovewebprojects_1

But I have often faced this problem: when I run mvn eclipse:eclipse on a Maven Web Project to convert it to an Eclipse project, it is not recognised as a Web Project by Eclipse. When I right-click on the server and select Add Remove Projects, it does not appear in the option box. But to me  mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true is indispensable as it downloads and links all the sources and JavaDocs, which comes very handy. On the other hand if I cannot add my project as a Web Project in Eclipse, running and debugging becomes a big issue. So how do I reconcile these two?

Solution 1: Specify the WTP Version

While running mvn eclipse:eclipse, specify the WTP Version by passing the -Dwtpversion=2.0 argument. The command looks like:

mvn eclipse:clean eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true -Dwtpversion=2.0

Note that as of this writing, the supported versions of WTP are  1.0, 1.5, 2.0 and R7.

Solution 2: Convert it to a Facted Project

Right click on the project, go to Properties, then select Project Facets.

converttofacetedproject

Another dialog appears having the available facets.

selectdynamicwebproject

Select Dynamic Web Module.

Solution 3: Manual editing

I like this best as it gives lot of flexibility around configuration. First you need to modify the .project file as shown:

Then, inside the .settings directory, you need to create two files called org.eclipse.wst.common.component and org.eclipse.wst.common.project.facet.core.xml.

org.eclipse.wst.common.component

org.eclipse.wst.common.project.facet.core.xml

Creating an EAR with Maven

Maven is the build tool of choice for many people due to the simplicity and flexibility of use. The real strength of Maven is vetted when handling real complex projetcs consisting of tens of modules, each requiring elaborate build requirements.

I had faced an uphill task of Mavenising one of our EAR projects. As is the typical case, our project consisted of a EJB module and a WAR module, package together in a EAR module. It was a bit complex as we had to deploy the same application in JBoss and Glassfish. I will write some of that experience here.

Let us consider an enterprise application having a structure as show below:

Project Structure

I will briefly explain what the modules stand for:

  1. swayam-ear: This is the enterprise application
  2. swayam-ejb: Is the EJB module
  3. swayam-war: Is the web module
  4. swayam-shared: Has the ejb remote interfaces. As the name indicates, its shared by the sawaym-ejb and the swayam-war modules
  5. swayam-ear-builder: Used for building all the modules

I am using Netbeans (6.8) and Glassfish for convinience. But you can pretty much use anything.

I have kept things pretty simple. This is how the Remote interface looks like (its a Stateless Session Bean):

And this is how I access it from the servlet:

Mavenising the EJB

We will use the maven-ejb-plugin for this. This is how the pom looks like:

Note that the packaging is ejb and not jar.

Mavenising the WAR

Mavenising the EAR

The most important thing here is the type tag inside the dependency tag. Without this, it will not work.

Putting it all together

Its often very cumbersome to build these modules one by one manually when one of them changes. This is more so in a development environment. So, I will conclude with one pom for building all the modules at one go. This pom is present in the swayam-ear-builder module.

Note that the path of the modules are relative to the pom.
You can build the EAR project and deploy it on Glassfish or JBoss. Once successfully deployed, you can open http://localhost:8080/swayam-war/EjbInvoker This is how it looks like:

screenshot-servlet-ejbinvoker-google-chrome

Resources

  1. Sources: https://github.com/paawak/blog/tree/master/code/swayam-ear-example
  2. Binaries: https://github.com/paawak/blog/blob/master/code/swayam-ear-example/swayam-ear/dist/

[How To] Configure GTalk on Kopete

Kopete is one of the most versatile and cool Instant Messenger for Linux. Its lot better and more secure and feature rich than Pidgin. GTalk is based on the open source XMPP Protocol, Jabber compatible.

While entering the new account details, select Jabber:

Select type as "Jabber"

Enter your full email id.

Go to the connection tab. Check the Override default server information check-box and enter the server as talk.google.com, the port as 5223. Also check these check boxes:

  1. Use protocol encryption

  2. Allow plain text password authentication

Connection details

Save this information and you should be done.

Tweaking MySQL on Fedora

MySQL is installed on Fedora and most Linuxes by default. Its just about some tweaking before you can use it. I am detailing some of the rather useful commands.

To Install MySQL and start it

mysql_install_db
mysqld_safe &

Make MySQL case insensitive

This is useful when the DB Script is also expected to run on Windows server.

vi /etc/my.cnf

[mysqld]
lower_case_table_names=1

To change the root password

mysql>

update user set password=password(“newPassword”)  where user=’root’;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

grant all on *.* to ‘root’@’192.168.%’ identified by ‘newPassword’;

FLUSH PRIVILEGES;

Adding a user

mysql>

insert into user (host, user, password) values(‘localhost’,’newUser’,password(‘xx123’));

insert into  host(host,db,Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv)  values(‘localhost’,’dbName’,’Y’,’Y’,’Y’,’Y’,’Y’,’Y’);

grant all on dbName.* to ‘newUser’@’localhost’ identified by ‘xx123’;

FLUSH PRIVILEGES;

[How To] Enable VPN on Linux by PPTP

PPTP is an wonderful utility to enable VPN on a Linux box. Its secure and compatible with Windows network. I first heard about PPTP from (this wonderful guy called) Nikolaj. I have learnt how to set it up from him.

I am detailing the steps here:

1> Install PPTP

yum install pptp

2> vi /etc/ppp/options.pptp

###############################################################################

# $Id: options.pptp,v 1.2 2005/08/20 13:16:38 quozl Exp $

#

# Sample PPTP PPP options file /etc/ppp/options.pptp

# Options used by PPP when a connection is made by a PPTP client.

# This file can be referred to by an /etc/ppp/peers file for the tunnel.

# Changes are effective on the next connection. See “man pppd”.

#

# You are expected to change this file to suit your system. As

# packaged, it requires PPP 2.4.2 or later from http://ppp.samba.org/

# and the kernel MPPE module available from the CVS repository also on

# http://ppp.samba.org/, which is packaged for DKMS as kernel_ppp_mppe.

###############################################################################


# Lock the port

lock

# Authentication

# We don’t need the tunnel server to authenticate itself

noauth

persist

debug

# We won’t do EAP, CHAP, or MSCHAP, but we will accept MSCHAP-V2

refuse-eap

refuse-chap

refuse-mschap


# Compression

# Turn off compression protocols we know won’t be used

nobsdcomp

nodeflate


# Encryption

# (There have been multiple versions of PPP with encryption support,

# choose with of the following sections you will use. Note that MPPE

# requires the use of MSCHAP-V2 during authentication)


# http://ppp.samba.org/ the PPP project version of PPP by Paul Mackarras

# ppp-2.4.2 or later with MPPE only, kernel module ppp_mppe.o

# {{{

# Require MPPE 128-bit encryption

#require-mppe-128

# }}}


# http://polbox.com/h/hs001/ fork from PPP project by Jan Dubiec

# ppp-2.4.2 or later with MPPE and MPPC, kernel module ppp_mppe_mppc.o

# {{{

# Require MPPE 128-bit encryption

#mppe required,stateless

# }}}


lcp-echo-failure 36

lcp-echo-interval 5

lcp-max-failure 0

3> vi /etc/ppp/chap-secrets

# Secrets for authentication using CHAP

# client                  server        secret                        IP addresses


VPNUserName      PPTP       VPNPassword         *

4> Create a file called /etc/ppp/peers/my-company-vpn

#pty “pptp my-company.com –nolaunchpppd”

name VPNUserName

remotename PPTP

require-mppe-128

file /etc/ppp/options.pptp

ipparam my-company-vpn

5> Then on the prompt:

pptp my-company.com call my-company-vpn

6> After 10/15 seconds, on the prompt:

route -n

You should see something like:

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.1.162 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0

87.61.21.102 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0

192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0

If you see ppp0, it means you have successfully connected to the VPN.

7> Add required routes

route add -host 192.168.1.30 gw 192.168.1.162

Where 192.168.1.30 is my internal company IP.

8> After that, to resolve the domains by names

vi /etc/resolv.conf

#to use when connected to the VPN my-company.com

domain my-office.my-company.com

#this, is the most important line: courtesy: Nikolaj

search my-office.my-company.com

#nameserver 192.168.1.1

nameserver 192.168.1.4

nameserver 192.168.1.5

Further reading:

[How To] Rip VCD on Linux

I have always had problems while playing VCDs on my Linux machine. The VCD file system is still not supported by the Linux kernel. After browsing the net and trying out various options, I will enlist the following which I find most useful.

Using cdrdao

This is the most flexible command and copies the contents of VCD in the .bin and .toc format. This can be played by mplayer, or can be burnt into another cd. First we need to determine the device name for the cd drive. We do this either by:

parted -l

or

cdrdao scanbus

Suppose the device is /dev/sr0. We then need to unmount this device:

umount /dev/sr0

Next, the following command will extract the contents of the VCD into .bin and a .toc files:

cdrdao read-cd –read-raw –read-subchan rw_raw –datafile fileName.bin –device /dev/sr0 –driver generic-mmc-raw fileName.toc

We can directly play the .bin file using mplayer. In case we want to create an iso from the .bin and .toc, we can use the bchunk. In order to install it, just do:

yum install bchunk

bchunk works only with cue. So, you need to convert the .toc to .cue:

toc2cue fileName.toc  fileName.cue

Then:

bchunk -v -r fileName.bin fileName.cue fileName

This will give you .iso

Using mencoder

mencoder vcd://2 -oac lavc -ovc lavc -o fileName.avi

Using vcdxrip

vcdxrip -i /dev/sr0 -v -p -t 1 –nofiles –nosegments

Here i denotes the mount point of the CDROM drive,  t denotes the Track Number. This way, a VCD can be ripped from a Linux machine. I have tested this on Fedora (10) and it works great.

Further Reading

The following sites have more detailed info about the above: