How to make STS add src/main/webapp as source folder?

I’d like STS to add src/main/webapp as source folder, but it never does, and if I do it manually, then Refresh Source Folders loses it anyway. I created a defect for STS (, but in the process of explaining I was asked to inquire here about this.

Did you apply the ‘eclipse-wtp’ plugin? If not, does applying it solve the problem?

Hi Peter, it didn’t help at all, sadly.

Why do you want this as a source folder in Eclipse? It isn’t a source folder from Gradle’s perspective. All that Gradle does with ‘src/main/webapp’ is to include its contents in the War, unchanged.

And if I do need it (I will look into this), isn’t there a way to do it?

With Gradle there is almost always a way, but in this case it will take a bit of effort. The best way I can see is to post-process the ‘.classpath’ file. For details, see the DSL reference for EclipseClasspath.

Perhaps my idea isn’t clever to begin with. I just thought STS should pick this up:

sourceSets.test.runtimeClasspath += files(“src/main/webapp”)

That’s adding it to the class path, not as a source folder.

If you want to make it working with STS, the only way I can think of is register this folder as a java source dir in Gradle. It’s not correct (because it’s not a java source dir) but it might help: 'src/main/webapp'

Can you tell us why you need this folder a source dir in eclipse?

Hi Szczepan, thanks for your input. Originally, I had my spring servlet.xml file in my WEB-INF folder next to web.xml, which was in src/main/webapp. I wanted to make this file accessible for the tests running outside and from STS. I could add src/main/webapp as a source folder but then STS would lose it when I used Refresh All.

For now I moved the Spring servlet file to src/main/resources and provided a custom location of it in web.xml using init-param contextConfigLocation.