I'm developing a WebService in Java using NetBeans and using gradle as depency maagement.
I found this article about developing web projects with gradle. It uses the Gretty plugin. I followed the instructions ( just changed the servlet container from jetty to tomcat ) and could develop/deploy a web project and open the "home page" from the servlet.
The problem is my WebService classes are not working properly. All GET requests made from my browser retus 404 error code. For testing, I made a new WebProject using Netbeans but this time without Gradle and it works like a charm.
Here follows the code:
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:+'
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
gretty {
port = 8088
contextPath = '/sisvendas'
servletContainer = 'tomcat8'
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.10'
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0.1'
}
The Resource:
@Path("produtos")
public class ProdutosResource {
@Context
private UriInfo context;
public ProdutosResource() {
}
@GET
@Produces("application/json")
public String getJson() {
// Just for testing...
retu "{"produtos":"arroz"}";
}
@PUT
@Consumes("application/json")
public void putJson(String content) {
}
}
Application config class:
public class ApllicationConfig extends Application{
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resourcesSet = new java.util.HashSet<>();
adicionarClassesRecursos( resourcesSet );
retu resourcesSet;
}
private void adicionarClassesRecursos( Set<Class<?>> resources ) {
resources.add( com.gear.dev.webprojectgradle.resources.ProdutosResource.class );
}
}
And this is the url for GET: http://localhost:8088/sisvendas/produtos
As I said before, the following request works: http://localhost:8088/sisvendas/ ( There is also a index.html file which is useless )
What i'm doing wrong?
