1

I´m using an embedded tomcat in my maven project to do some integration tests (client - server scenario).

Tomcat tomcat = new Tomcat();
//set Host and port..
//add user and role for basic authentication
tomcat.start()

If I build the project with maven the tests are running as expected and the server starts properly. If I try to debug the tests via Eclipse the tomcat server doesn´t start with the exception:

org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]

I tried to debug the tomcat.start() method to figure out where the exception occures. It´s in (StandardServer.class):

synchronized (services) {
        for (int i = 0; i < services.length; i++) {
            services[i].start();
        }
    }

Services is at the state [StandardService[Tomcat]], so I actually doesn´t know much more than before since I get no stack trace. The exception is caught in this snippet (LifeCycleBase.class):

try {
        startInternal();
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        setStateInternal(LifecycleState.FAILED, null, false);
        throw new LifecycleException(
                sm.getString("lifecycleBase.startFail",toString()), t);
    }

Im using Eclipse Version: Neon Release (4.6.0). Some colleagues uses eclipse too and it works in one case. We tried to figure out the difference but didn´t find much. What we´ve tried so far is to edit the build paths of some dependencies of our project. Of course we did change our own project dependencies only. The other libraries e.G. embedded tomcat are untouched.

In Netbeans it works as expected. I assume it´s an eclipse setting or something like that..

Edit:

I guess I´m not providing enough information. The dependencies of the pom.xml looks like:

<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-core</artifactId>
  <version>7.0.55</version>
</dependency>

<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-logging-log4j</artifactId>
</dependency

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper</artifactId>
  <version>7.0.55</version>
  <exclusions>
    <exclusion>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
  <scope>provided</scope>
</dependency>

I tried to remove the dependency of javax.servlet and the exclusion. After I do this, the tomcat server starts but there are more than 200 tests failing. So I need this dependency. This post explains the difference between this two dependencies. But I still don´t get, why it doesn´t work..

Community
  • 1
  • 1
monti
  • 455
  • 7
  • 25
  • Maybe there is a hint in the eclipse log: https://wiki.eclipse.org/FAQ_Where_can_I_find_that_elusive_.log_file%3F – Gimby Oct 06 '16 at 09:19
  • I cleaned the log and execuded the tests via RunAs -> Junit again. There are only 3 messages which says "Warning: Enviroment variable Home is not set." But it also says it uses my /Users/ directory instead. The 2 leaving messages are information that some css and logger references are not bind. – monti Oct 06 '16 at 09:38
  • I updated the post to provide some more information. – monti Oct 07 '16 at 10:25
  • What version of javax.servlet-api does tomcat-jasper pull in? You can see this when you open the pom.xml and then click on the dependency hierarchy tab at the bottom – Gimby Oct 07 '16 at 10:55
  • And just to clarify that: I think you're asking completely the wrong question. The question is more why the tests fail, the tomcat server apparently starts just fine if you don't manually meddle with its dependencies. – Gimby Oct 07 '16 at 11:01
  • mh, maybe. I still wonder why it works in netbeans and in one eclipse installation. That´s why I thought it´s an eclipse problem. I guess you´re right, now I wonder why some tests fail. By the way: the tests fail ONLY in eclipse. With maven it works fine. I updated the version numbers. The version of tomcat and tomcat-jasper is 7.0.55. I don´t see any dependency in the hierarchy called javax.sevlet-api. Everything in the tree of tomcat-jasper is 7.0.55 (e.G. tomcat-servlet-api). – monti Oct 07 '16 at 11:28
  • You did leave out the exclusion, right? – Gimby Oct 07 '16 at 11:29
  • 1
    Tests in Maven are handled by Surefire plugin, which is not present in Eclispe Junit runner. In other words, runnig tests via Maven an Eclipse are two completely different things. The problem might be caused by the missconfiguration of your tests (e.g. how you acctualy start your Tomcat instance for testing purposes). It is hard however to give any advice, without seeing how you have done it. Cound you provide full pom.xml and some exemplary test with its configuration? – Tinki Oct 07 '16 at 11:29
  • @Gimby yes I did. I removed the exclusion and the second dependency of javax-servlet. – monti Oct 07 '16 at 11:31
  • 1
    Well then the exclusion is pointless to begin with :) In an case what Tinki says is very relevant; the difference between Netbeans and Eclipse is that Netbeans actually uses Maven for everything including running the tests, while Eclipse basically only adopts projects settings from Maven. The question as asked is a dead end, it needs to be about getting the tests to succeed in Eclipse. – Gimby Oct 07 '16 at 11:34
  • Thanks for the information. I did not know that. The full pom can be found here: https://github.com/apache/olingo-odata4/blob/master/fit/pom.xml#L115 I actually try to help to refactor the "fit" module. The tests can be found in https://github.com/apache/olingo-odata4/tree/master/fit/src/test/java/org/apache/olingo/fit – monti Oct 07 '16 at 11:38
  • The Tomcat Server gets started in https://github.com/apache/olingo-odata4/blob/master/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java#L55 – monti Oct 07 '16 at 11:45
  • Not sure if I should open a new Question for this. This is a client - server scenario and the client consumes some stuff from some static services. The tests based on the static services fails with HTTP Not Found. So the static services aren´t "loaded". – monti Oct 07 '16 at 12:58
  • Thanks for leading me into the right way. I found the problem and the made the tests working so far. There is only 1 failure and some minor errors now which isn´t part of the question. But I really appreciate the help you provided. I was kinda deadlocked. =) – monti Oct 08 '16 at 22:30

0 Answers0