5

I've been developing a standard web app and its really annoying to have Eclipse show src/main/resources and src/main/java in such a convenient flat-package way, yet I have to frequently drill down into src/main/webapp and all its subdirectories to modify my css, js, and html files.

I've never seen a project use additional source folders for resources like those, but is it out of the question to try? Ideally I'd love to have a directory structure like

src/main/java
src/main/resources
src/main/jsp
src/main/javascript
src/main/css

Has anyone setup a project like this? Does it become more of a hassle to even try, breaking existing plugins and whatnot?

1
  • 2
    The above sounds like a webapp and therefor put the things like jsp, javascript and css into src/main/webapp/ folder ... so no need for supplemental resources configuration. Commented Jun 11, 2013 at 11:46

1 Answer 1

7

Add resource folders this way.

<project>
 ...
 <build>
   ...
   <resources>
     <resource>
       <directory>resource1</directory>
     </resource>
     <resource>
       <directory>resource2</directory>
     </resource>
     <resource>
       <directory>resource3</directory>
     </resource>
   </resources>
   ...
 </build>
 ...
</project>

More information

However, if you want multiple web resources (WEB-INF directory in WAR file) than you need to configure Maven War plugin.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.3</version>
      <configuration>
        <webResources>
          <resource>
            <directory>src/main/jsp</directory>
          </resource>
          <resource>
            <directory>src/main/javascript</directory>
          </resource>
          <resource>
            <directory>src/main/css</directory>
          </resource>
        </webResources>
      </configuration>
    </plugin>
  </plugins>
</build>
Sign up to request clarification or add additional context in comments.

4 Comments

That looks right to me. Whether IntelliJ and Eclipse deal with that properly is another story...they should though. The IDEs start to show their limitations when you use something like Build Helper Maven Plugin (mojo.codehaus.org/build-helper-maven-plugin) to add source directories. Cheers.
Isn't this just going to put all the resources on the classpath instead of in the WEB-INF folder where html resources need to go?
Yes it will, but this how I understood your question. You probably wanted to have multiple webapp directories merged into one?
Thats correct, I was looking for a way to separate my webapp resources and have them all merge into webapp at the end- thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.