1

I'm new to maven and I've been trying to include some assets such as images and sounds in my exported .jar, but it doesn't seem to work. I'm trying to copy them in 2 separate folders one in ${basedir}/resources/Textures and the other in ${basedir}/resources/Sounds. The maven-resource-plugin doesn't copy anything at all while the tag only copies them in the basedir and the the application doesn't see them

This is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>me.Moshu</groupId>
    <artifactId>Atestat</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>Alien Attack</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.8.1</maven.compiler.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>




    <build>

        <plugins>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>copy-resources-1</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/resources/Sounds</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/resources/Sounds</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-resources-2</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/resources/Textures</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/resources/Textures</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>

                            <archive>
                                <manifest>
                                    <mainClass>
                                        com.Moshu.Atestat.Main
                                    </mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <source>9</source>
                    <target>9</target>
                </configuration>
            </plugin>


        </plugins>

    </build>


    <dependencies>

        <dependency>
            <groupId>org.imgscalr</groupId>
            <artifactId>imgscalr-lib</artifactId>
            <version>4.2</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.swinglabs/swingx -->
        <dependency>
            <groupId>org.swinglabs</groupId>
            <artifactId>swingx</artifactId>
            <version>1.6.1</version>
            <scope>compile</scope>
        </dependency>


    </dependencies>

</project>
Moshu
  • 11
  • 1
  • Why are you copying file from one resources location to another. Does not make sense. Furthermore the compiler-plugin configuration says Java 9 but the properties say something different? Also using a stone age old maven-resources-plugin ? Can you give which Maven versions / JDK version you are using? Keep your assets simply in `src/main/resources/` and they will automatically being packaged into the resulting jar file... ? – khmarbaise Jan 20 '22 at 21:34
  • Well, I just copied a config I found related to my problem, that's where the nonsense is coming from :)). I'm using Java 9 and maven 3.8.1. And yes that was the problem, apparently, I had 2 resources folders and I got them mixed up. Thank you! – Moshu Jan 20 '22 at 21:43
  • You should also define the versions of the plugin via pluginManagement for example for maven-assembly-plugin, maven-compiler-plugin, maven-resources-plugin etc. – khmarbaise Jan 21 '22 at 06:03
  • If you are using JDK9 (which is out of date) you can use only the defined properties instead of a configuration block for maven-compiler-plugin. Furthermore I would suggest to use `9` instead. – khmarbaise Jan 21 '22 at 06:04

0 Answers0