4

I have an enterprise application I have been developing in Netbeans, and I'm now trying to add some RESTful web services to the -war module. The problem I'm having is that when I use the Netbeans feature to create the web services, no ApplicationConfig.java class is being created.

All the examples and tutorials I've found on the web explain that Netbeans will automatically generate an ApplicationConfig.java class that extends Application, and by editing the @ApplicationPath annotation on this class, I can configure the URI at which the web services will be reachable. And in fact, if I create a new Java EE application from scratch, and then invoke New --> RESTful Web Services from Patterns, this is exactly how it works. But when I try this with the Netbeans project I am developing, no ApplicationConfig.java is created.

My questions:

1) Any idea why this is happening? Netbeans bug? Are there some known circumstances in which Netbeans does not create an ApplicationConfig?

2) Can I just create an ApplicationConfig.java myself manually? I have seen examples (not with Netbeans) that use an empty ApplicationConfig class which does nothing except provide a place to put the @ApplicationPath annotation to allow that part of the URI to be configured. If I do this, will Netbeans get confused?

3) I see that when Netbeans creates this class, it includes code that overrides the Application.getClasses method. It looks simple enough to manually create my own code that does exactly the same thing that the automagically generated code would do. Do I need it?

Details of my environment are:

  • Product Version: NetBeans IDE 8.1 (Build 201510222201)
  • Updates: NetBeans IDE is updated to version NetBeans 8.1 Patch 1
  • Java: 1.8.0_92; Java HotSpot(TM) 64-Bit Server VM 25.92-b14
  • Runtime: Java(TM) SE Runtime Environment 1.8.0_92-b14
  • System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
  • Project type: Java EE 7 application
  • Server: Wildfly 9.0.2

Thanks!

Duncan

Duncan
  • 507
  • 3
  • 14

4 Answers4

2

Yes, you can create it manually but you have to create it in the same package with your WebServicesClasses, example:

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

@javax.ws.rs.ApplicationPath("webresources")
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) {
        //add all resources classes
        resources.add(jaca.server.webservice.PersonWebService.class);
    }
}

Clean and build your project, or restart your netbeans because the first times does not work.

Community
  • 1
  • 1
alexcornejo
  • 163
  • 1
  • 12
  • Yes, it's been a while, but I think that's exactly what I did. But I must say, an answer that includes "restart your netbeans because the first times does not work" makes me wonder if Microsoft has taken over development. That's something the developers need to take a look at. – Duncan Apr 28 '17 at 15:47
1

NetBeans didn't create ApplicationConfig.java for me either. The thing was that I created a Web Application Project, then added my resources (REST operations).

If I create the Web Application Project however and add 'New RESTful Web Services from Patterns' before adding my own resources, then it creates the ApplicationConfig for me automatically.

EricG
  • 3,788
  • 1
  • 23
  • 34
1

Not sure if this still relevant, but I had the same problem with Netbeans 8.2 and after a lot of toss and turn, I manage to get the ApplicationConfig.java file automatically created by changing the project name. So I guess if you create the project the first time and try to delete and create a project with the same name, it will not create the file. Hope that helps someone.

0

NetBeans adds some hint in the name of the class after you add the annotations, there it must give you the option to add the ApplicationConfig.java class, and also other options related to Jersey.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38