Maven add properties file to jar file

47,776

Solution 1

Add file in the same package (folder) in src/main/resources instead of src/main/java or see my answer With maven - clean package, xml source files are not included in classpath

Solution 2

I did it this way and function perfectly.

    </dependencies>
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Share:
47,776
AKZ
Author by

AKZ

Updated on July 28, 2022

Comments

  • AKZ
    AKZ almost 2 years

    I am using the following plugin configuration to make a jar file and I want to include non-java src files in the same place in the output jar as described here.

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <compilerArgument>-Xlint:all</compilerArgument>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>   
                <!-- include non-java src files in the same place in the output jar -->
                <resources>
                    <resource>
                        <directory>src/main/java</directory>
                        <includes>
                            <include>**/*.properties</include>
                        </includes>
                        <filtering>true</filtering>
                    </resource>
                </resources>                                     
            </configuration>  
    

    The above does not work and neither does the following:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <!-- include non-java src files in the same place in the output jar -->
                <resources>
                    <resource>
                        <directory>src/main/java</directory>
                        <includes>
                            <include>**/*.properties</include>
                        </includes>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </plugin>        
    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <compilerArgument>-Xlint:all</compilerArgument>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>                    
            </configuration>                
        </plugin>