I have created a very basic Java Web Application with Netbeans 8.2
Here is the steps i have done:
Here what i have put in this java class:
package pkg1;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
public class TestService
{
@Path("/test")
@GET
@Produces("text/plain")
public String methode_test()
{
return "Hello test";
}
}
I have no compilation problem. GlassFish is launched, but i got a 404 error if i try to go to /test url...
Any idea ?
Thanks
I made a couple of small changes to get your code working using NetBeans 8.2, JDK 8 and Glassfish 4.1.1 on Windows 10:
@Path
annotation on the class as well as methode_test()
.This is the revised TestService
class:
package pkg1;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("/demo")
public class TestService
{
@Path("/test")
@GET
@Produces("text/plain")
public String methode_test()
{
return "Hello test";
}
}
This is the additional class you need to add:
package pkg1;
import javax.ws.rs.core.Application;
@javax.ws.rs.ApplicationPath("sample")
public class ApplicationConfig extends Application {
}
My project was named DemoService, and therefore had a context root of DemoService, but in your case the URL to use would probably be: http://localhost:8080/TestService/sample/demo/test
Notes:
For convenience you can set the default path to be used in the browser when testing your project:
NetBeans 8.2 provides a basic "Hello World" REST application that you can create in just a few seconds using the Project Wizard: File > New Project... > Samples > Web Services > REST: Hello World.