M
M
Marat2016-07-13 18:24:23
Java
Marat, 2016-07-13 18:24:23

How to set Maven to copy at build time?

There are directories outside the Java project. These are not resources (they must be copied to a directory other than target\classes).
Maven builds the Jar into target\jfx .
Upon completion of the build via maven, it is necessary that they be copied, that is, we specify SourceDir= ~/fluent/mapGr + DestinationDir={project.basedir}/target/jfx/speedmap and forward.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vamp, 2016-07-13
@Joysi75

This is done using plugins. Here is a choice of antrun and maven-resources-plugin:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <configuration>
                        <tasks>
                            <copy todir="${project.basedir}/target/jfx/speedmap">
                                <fileset dir="/home/fluent/mapGr"/>
                            </copy>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.1</version>
            <executions>
                <execution>
                    <id>copy-resources-foreign</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.basedir}/target/jfx/speedmap</outputDirectory>
                        <resources>
                            <resource>
                                <directory>/home/fluent/mapGr</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

There are directories outside the Java project. These are not resources (they must be copied to a directory other than target\classes).

In your case, these are still resources. It's just that by default, maven considers only content from the src/main/resources and src/test/resources directories as resources. You just need to say where else the resources needed to build the project are located.
Generally speaking, it is not very good to be tied to resources external to the project. This makes it harder for new contributors to join, as it's no longer enough to just run mvn install and get the finished artifact. And then you yourself will forget / get confused, you will spend time remembering how to assemble the project correctly. Although, of course, the owner is a gentleman.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question