0

I have two maven modules: common and webapp.

They have the same parent project, and webapp depends on common.

There is a class MapServer in common module:

public class MapServer {
    public TileResponse getTileResponse(Coord coordinate, int size, String format, String[] layers) {
        ....
        return null;
    }
}

I can run it like this:

public static void main(....){
    ....
    TileResponse tileResponse = mapServer.getTileResponse(coord, 256, "png", new String[]{"layer"});
}

It worked (got the desired result without any errors).

However once I run the webapp module through servlet,

public class ServeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
            ......
            tileResponse = mapServer.getTileResponse(coord, 256,format , layers.split(","));
    }

}

I got the error:

July 04, 2014 5:55:36 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [tile] in context with path [/test] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoSuchMethodError: MapServer.getTileResponse(Lcore/Coord;ILjava/lang/String;[Ljava/lang/String;)LTileResponse;

What's going on?

I am using tomcat maven plugin:

<build>
    <finalName>webapp</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <port>8080</port>
                <path>/test</path>
                <uriEncoding>UTF-8</uriEncoding>
                <finalName>gtwebapp</finalName>
                <server>tomcat7</server>
            </configuration>
        </plugin>
    </plugins>
</build>

1 Answer 1

2

A java.lang.NoSuchMethodError indicates that the version of a class (in your case MapServer) used to build the calling code is different to the version available at runtime.

Once you are happy with the working version of MapServer:

  • Rebuild the common project and install it into your local maven repo
  • Rebuild the webapp against this version of the common project
  • Redeploy the webapp on tomcat before trying again
Sign up to request clarification or add additional context in comments.

4 Comments

@hguser If you make a change to the common module, it will not be automatically picked up by the webapp module unless you rebuild them all. You need to be careful with maven that your webapp doesn't pick up an old version of your common module. That is why I outlined the steps above.
You mean even I change my codes in the common module, but the webapp module may still use and old version of the jar from my local repository?
@hguser If you don't rebuild your common module and make it available to the webapp in the local repository then yes, the webapp will continue to use the existing (old) jar in the local repository.
Thanks, seems you are right, it works after I rebuild the common module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.