Web Application new project wizard customize Servlet version

Answered

Our plugin creates a new entry in the Java new application wizard as a child of Web Application.

Currently, Web Application defaults to creating a web.xml with servlet version 3.1. I'd like to customize this to force version 2.5 (and in the future be able to vary the version based on selections in our new application wizard panel).

If possible, could you point me in the right direction?

1
5 comments

hi, 

1. code

StartupManager.getInstance(module.getProject()).runWhenProjectIsInitialized(() -> {
for (WebFacet webFacet : WebFacet.getInstances(module)) {
final WebApp webApp = webFacet.getRoot();
if (webApp != null) {
webApp.getVersion().setStringValue("2.5");
}
}
});

2.   extension point

com.intellij.javaee.supportProvider.JavaeeFrameworkSupportContributor
1

Thanks Sergey,

 

Did you meant to suggest that I add that Startup callback in my JavaeeFrameworkSupportContributor extension? 

Maybe I'm misunderstanding your suggestion, but it looks like JavaeeFrameworkSupportContributor#setupFrameworkSupport gets invoked after the web.xml file gets generated. I need the project wizard to generate a web.xml with my specified servlet version. This still resulted in a web.xml with Servlet version 3.1.

 

Thanks again for the help.

 

 

0

Follow up:

 

Looking again I see that your suggestion entails modifying the xml model directly. This makes sense, but it did not work. I'll investigate more, but any suggestions welcome.

0

As a side question: is there a way, instead of updating the web.xml's xml model directly, to modify the Servlet version at a higher level (e.g. similar to what selecting a different servlet version from the dropdown in the new project wizard would do)?

See JavaeeFrameworkSupportProviderBase#addSupport: ConfigFileVersion determines what version gets created, but I don't know of any way to hook into this.

I'd like to hear your opinion on this, but this approach seems more robust: for example, I'd also like the schema url in web.xml to be updated to reference the updated servlet version.

0

Another update:

 

Looks like your original suggestion works. I just had to wrap the write in a write action.

0

Please sign in to leave a comment.