1 year ago

#76985

test-img

Moshu

Copy resources into sepparate folders in the jar with maven

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>

maven

maven-3

maven-resources-plugin

0 Answers

Your Answer

Accepted video resources