George
George

Reputation: 75

Can't add resources to jar in maven

This is my problem: I have a Maven project that is using a Swing library and it is a GUI app which I want to include a resources (images and one config.properties file) in my jar file.

Here is my pom.xml code:

  <build>
    <resources>

      <resource>

        <directory>${basedir}/resource</directory>

            <includes>
                <include>**/*.png</include>
            </includes>

        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>

      </resource>

      <resource>
        <directory>${basedir}/config</directory>

        <includes>
            <include>config.properties</include>
        </includes>

        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>

      <resource>
        <directory>.settings</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>


    </resources>



    <plugins>
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
         <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>bis.debug.mode.ui.MainBISDebugMode</mainClass>
            </manifest>
         </archive>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>


  </build>
</project>

and here is my structure to my project:

Project structure

I included directories as it seen in the pom.xml and the files in it and still doesn't included in jar file and it doesn't see images on the GUI app. When I run the program as Java application everything is fine.

Is it possible to be something wrong in my code? How I can fix the problem?

Upvotes: 2

Views: 9645

Answers (1)

Azzabi Haythem
Azzabi Haythem

Reputation: 2413

You need only to put your config file in src/main/resources and no need to add resources in pom.xml because src/main/resources is the maven's default resources folder

Upvotes: 4

Related Questions