tags:

views:

167

answers:

2

Hi All,

I have a java application for exaple see below.

myProject
  |
  |----src
  |     |
  |     |--main
  |     |
  |     |--resources
  |           |   
  |           |--userConfig.properties
  |           |--log4j.properties
  |
  |---target

I am using Maven to build my project .I am using maven command to build jar file.

mvn package -DMaven.test.skip=true

I want to exclude userConfig.properties file from my jar file so i have mentioned in pom.xml as below.

<excludes>
        <exclude>**/userConfig.properties</exclude>        
  </excludes>

but it will exclude from the target folder in which compile code resides. And Application will not run because it will not find the userConfig.properties.

Can anyone help me ?

Thanks Nisarg Mehta

A: 

You shoud take a look at this.

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <excludes>
            <exclude>**/userConfig.properties</exclude>
          </excludes>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>
RC
+1  A: 

I think you're probably already doing it correctly, depending on where you configured that exclude (check with jar tf what files really are in your jar). Most likely, you're running into trouble because the file is not on your classpath and thus your app can't find it. Try adding the directory with the resources file in it to the classpath.

You might want to put in some defaults and let the application read in its configuration from a predefined path, to avoid having to mess with the classpath.

wds