Friday 7 January 2011

Maven settings for deployment using scp

Create a file settings.xml in ~/.m2 that's C:\Documents and Settings\iwright\.m2 in my case using cygwin on XP

Create a server entry with the necessary info e.g. if using ssh
<servers>
<server>
<id>cggh</id>
<username>iwright</username>
<privateKey>C:\Documents and Settings\iwright\.ssh\id_rsa</privateKey>
<passphrase>mypassphrase</passphrase>
<directoryPermissions>775</directoryPermissions>
<filePermissions>664</filePermissions>
</server>
</servers>

Note that if you are using cygwin then you will probably need to copy your .ssh directory from /cygwin/home/username to Documents and Setting\username

Run a deploy command
mvn verify install:install deploy:deploy

If the deployment repository isn't set in the pom then you can also define it using:
-DaltDeploymentRepository=cggh::default::scp://cloud1.cggh.org/var/www/maven

(Note the id cggh must match the id in settings.xml otherwise the permissions won't be resolved from the settings.xml)

Using Roo on an existing database

Creating a web application to update an existing database with Roo is extremely simple...

project --topLevelPackage org.cggh.quac --projectName quac --java 6
persistence setup --provider HIBERNATE --database MYSQL --databaseName drupal_users --userName drupal6 --password drupal6
database introspect --schema drupal_users
database reverse engineer --package ~.model --schema drupal_users
controller all --package ~.web

Some notes:
Make sure that the database has foreign keys set up
If you want security then run:
security setup

For password encoding:
(See https://jira.springsource.org/browse/ROO-1133)
Add the following to src/main/resources/META-INF/spring/applicationContext.xml
<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.MessageDigestPasswordEncoder">
<constructor-arg value="MD5" />
</bean>

Add the following to the Users class:
@Autowired
@Transient
transient private MessageDigestPasswordEncoder passwordEncoder;

private String pass;

public void setPass(String password) {
if(password==null||password.equals("")) {
return; //don't update password if blank is sent
}
String encodedPassword = passwordEncoder.encodePassword(password, null);
this.pass = encodedPassword;
}