How to packing Resources in Maven Project?

Posted by Rehman on Stack Overflow See other posts from Stack Overflow or by Rehman
Published on 2011-11-15T09:35:02Z Indexed on 2011/11/15 9:50 UTC
Read the original article Hit count: 415

I am looking for suggestion in putting image file maven web project. One of classes under src/main/java need to use an image file. My problem is, if i put image file under src/main/webapp/images then application server cannot find that path on runtime(where myeclipse can ) because war archive do not have specified path "src/main/webapp/images".

My question is where should i put the image file that my project can find it without prompting any error or exception.

I am using

  • Java Web Application with Mavenized falvour
  • MyEclipse 10
  • Application Server: JBoss 6

Currently i do have following dir structure

Project Directory Structure

-src/main/java
      -- classes
  -src/main/resources
     -- applicationContext.xml
  -src/test/java
      -- test classes
  -src/test/resources
       (nothing)

  -src
    -- main
        --- webapp
              --WEB-INF
              --Images
              --Css
              --Meta-INF
  -target
  -pom.xml

And pom.xml's build snippet is as follows

<build>
    <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
    <outputDirectory>${basedir}/target/${project.artifactId}/classes</outputDirectory>
    <resources>
      <resource>
        <directory>${basedir}/src/main/resources</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>${basedir}/src/test/resources</directory>
      </testResource>
    </testResources>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>${jdk.version}</source>
          <target>${jdk.version}</target>
          <optimize>true</optimize>
          <useProjectReferences>true</useProjectReferences>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
          <webResources>
            <resource>
              <directory>${basedir}/src/main/resources</directory>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>

Thanks in advance

© Stack Overflow or respective owner

Related posts about java

Related posts about maven-2