Dealing with Tomcat

I was modifying a project in Java with maven and Spring. In some point the need of having the application context XML outside Tomcat came out. In my case it was being loaded using the ContextLoaderListener. I tried other ways of loading it, but the issue is the same: the classpath.




I wanted to change path/to/application/context.

Tomcat doesn’t give the access to any file outside where it is running, so all the classpath have to behave this way. It is done this way for security reasons. After struggling a hard time, trying different things and almost give up, I decided to read how Tomcat works. I found this page: It have the answer to my question: add the path to the application context XML in the under the shared loader.


Hope this is useful for someone !

Annotations in Java

I am working on a new project using Java, Jersey, MongoDB with MongoJack, JUnit and maven.

As MongoDB is pretty fast the need of mockers can be avoided in tests. but the database needs to have the data.

In my case, there is a test just for that: it creates and saves all the data needed. The problems is that it has to be run before the other tests !

Instead of finding a way to give the tests an order, I just created a base class that all the testing classes extends and put a method with the annotation @Before. That method initialized all the necesary things (in my case MongoDB) and ran all the methods with @Test annontation in the class in charge of loading the data.

public abstract class BaseTest {

    public void startMongoConnection() throws UnknownHostException, InvocationTargetException, IllegalAccessException {
        if (!MongoConnection.isActive()) {
            EntitySavingTest entitySavingTest = new EntitySavingTest();
            for (Method method : entitySavingTest.getClass().getMethods()) {
                if(method.isAnnotationPresent(Test.class)) {

    protected void extraSetup() {


public class ATest extends BaseTest {

    public void extraSetup() {
        //Any extra things you need to have before the test starts

    public void test() {
        //Testing code...


Pretty simple and useful !

I got all the information about annotations here:

Two useful pages i found

  1. Some days ago i stumbled with this page:

    When i was coding in .NET it was quite hard to find good information. Great part of the community have a low level of programming skills. I had to look so many pages, it was stressing.

    I think the problem relies on the UI way to do thing of Microsoft. People tend to forget how things work.

    The articles in that blog are from high level programmers: they don’t only code, but understand how it works. The most interesting part is that they use C# to do advanced things.

  2. The other page i’ll like to suggest is:

    Awesome css framework. If you live web design, you will find everything you need there.