Tag: manual

Create simple project using Maven

Maven supports a simple mechanism to generate a project with the required structure and files already in place. Simply execute the command below:

mvn archetype:generate -DgroupId=com.test -DartifactId=mytest

Replace com.test and mytest with your preferred name and package for your project.

The maven documentation page contains a short list of the most common archtetypes. When you enter the command an interactive console will start from which you can select the preferred archetype to start with. You must enter the number of the archetype or you can specify a filter by packagename to shorten the list of options.

Leave a Comment

Spring autowire values in @Controller

The Java Spring framework allows you to annotate classes via the _@Controller _annotation. This allows you to maps requests and handle them via a MVC implementation. These classes can be detected automatically via a:

<context:component-scan base-package="example.class" />

The downside of this approach is that the values cannot be set anymore via a tag, because the class is already constructed. In order to still be able to set values in the class use the @Value annotation in the attribute fields of the class.

Leave a Comment

Use git-svn for SVN repositories

Recently I came across the possibility to use git to access SVN repositories. Basically you use the command

git svn ...

to checkout a SVN repository. This is then stored locally on your hard drive and accessible as an ordinary git repository. Updating your local checkout is done by issuing

git svn rebase

committing the changes back to SVN is done easily by issuing a

git svn commit

command.

This solution looks a very nice solution for older code sources which are still using SVN. There are some ifs and buts of course, with one the biggest remarks that branching and merging from your git-svn checkout back to SVN is discouraged because of the very different nature in branching between git and svn.

Leave a Comment

Apache .htaccess authorization with both IP check and password authentication

Have you ever been struggling to secure a website domain by both IP address whitelist and a password file? This means the user has to have a specific IP address to even be allowed, and after allowance the user must enter his/her password for access.

The solution to do this in a Apache .htaccess file is listed below.

Important things to notice are:

  • A password file is created using htpasswd in /home/domains/www.example.com/secure.passwd. This file can be located anywhere you like, as long as the user Apache runs as can read it
  • The line with Satisfy All is the key to the solution. If you want the user to only have to fulfill one of the two requirements (has whitelisted IP or enters password) set this to Satisfy Any.
AuthType Basic
AuthName "Secure site"
AuthUserFile /home/domains/www.example.com/secure.passwd
Require valid-user
Order deny,allow
Deny from all
#Repeat the line below for all allowed IP addresses.
Allow from 127.0.0.1
Satisfy All

Leave a Comment

Set Git user information

When starting to use git, you should set your username and emailaddress, which is stored for every commit. The git website contains a great guide on getting started. Execute the following two commands to set your commit information globally for every project.

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

If you want to set the information for a specific project, execute this command without the –global flag in the repositories folder. This will only locally change the information.

On another note, GitHub also has a great guide on getting started with the git basics.

Leave a Comment