2

Hello I am new to Tomcat development and have a question.

When I am trying to develop a REST Servlet it works under development with netbeans and tomcat 8, but when I try to create a .war file and load it to a remote tomcat via webinterface, it doesn't work.

So I just created a new Web Application in Netbeans and changed it a little bit:

@Path("test1")
public class GenericResource {

    @Context
    private UriInfo context;


    public GenericResource() {
    }


    @GET
    @Produces("application/xml")
    public String getXml() {

       return "<xml rest='cool'></xml>";
    }

}

and

    package test;

import java.util.Set;
import javax.ws.rs.core.Application;


@javax.ws.rs.ApplicationPath("test")
public class ApplicationConfig extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new java.util.HashSet<>();
        addRestResourceClasses(resources);
        return resources;
    }

    private void addRestResourceClasses(Set<Class<?>> resources) {
        resources.add(test.GenericResource.class);
    }

}

So when I deploy it in Netbeans it works perfectly to use

http://localhost:8080/ServerTest/test/test1

But when I create a war and develop it to remote tomcat - it only shows error 404 when I use "http://xyz.at/ServerTest/test/test1"

But why? I heard this shouldn't happen when I use servlet 3.0.

EDIT:
The index.html worked before - only the rest services (GET, POST) don't work yet.

It's funny because in netbeans it works perfectly.

I just noticed that in development I have tomcat 8.0.9 but on remote server I have 8.0.15 - does this make trouble?

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
  • i'm facing the same issue. did you manage it? – Sina Barghidarian Oct 25 '17 at 09:54
  • Sorry, I don't know exactly anymore because it was a long time ago. I think the solution was to explicit start the servlet-application in tomcat web manager. It was not activated per default. Did you solve your problem? If yes, how did you do? – Andreas Weswaldi Mar 12 '18 at 20:53

1 Answers1

0

Seems like you are putting it not to the root path.

As quick solution try to rename your war to ROOT.war and then deploy it.

You can read more about context path configuration here.

Community
  • 1
  • 1
Maksym
  • 4,434
  • 4
  • 27
  • 46
  • Thanks for your quick answer, but the index.html worked before - only the rest services (GET, POST) doesn't work yet It's funny because in netbeans in works perfect. I just noticed that in development I have tomcat 8.0.9 but on remote server i have 8.0.15 - does this make trouble? – Andreas Weswaldi Dec 02 '14 at 18:15
  • I am having same issue, have you found a solution? – techprat Jul 25 '18 at 05:47