0

I'm trying to build my project with Maven and libraries keep being dropped at /target. I was able to select a new output directory for my project's jar with the outputDirectory tag.

How I can select the directory for the needed jar files to run my program? I can specify which of them to save?

Edit(pom file):

<?xml version="1.0" encoding="UTF-8"?>
<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>CarlosRoma</groupId>
    <artifactId>TestTools</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <build>
        <plugins>          
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <!--Main class of the project here-->
                            <mainClass>TestToolClasses.TestTool</mainClass>
                        </manifest>
                    </archive>
                    <outputDirectory>C:\Users\Roma\Desktop\TestTool</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>install</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <updatePolicy>never</updatePolicy>
            </releases>
        </pluginRepository>
    </pluginRepositories>
    <repositories>
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <name>TestTool</name>
</project>

Thanks in advance!

  • Automatically, Maven does _not_ copy libraries to `target`. What have you specified in your `pom.xml` ? – J Fabian Meier Apr 01 '20 at 15:15
  • Furthermore, to build an executable jar, have you considered: https://stackoverflow.com/q/574594/927493 ? – J Fabian Meier Apr 01 '20 at 15:17
  • How I can select the directory for the needed jar files to run my program? == if you talk about your dependencies they are in the pom.xml file you should add there your needed jars, and maven will download them to to specified folder (by default Unix/Mac OS X – ~/.m2/repository Windows – C:\Users\{your-username}\.m2\repository) – Mammad Apr 01 '20 at 15:18
  • I will edit my post to add my pom.xml file. –  Apr 01 '20 at 15:24
  • Okey, pasted it –  Apr 01 '20 at 15:29
  • @Croma1994 I see what you are trying, but that is not how it is meant to be. Things are meant to be build to `target`, not to a fixed directory in your computer. Why do you want to have a different directory? – J Fabian Meier Apr 01 '20 at 15:48
  • To avoid manually creating it everytime. My program have the main folder and 2 more, one of them for the libs (.jar). I was hoping to automatize this process, but I see is advisable to do it manually. –  Apr 01 '20 at 16:17
  • 1
    You can automate that via Maven-Assembly-Pugin or Maven Shade Plugin ...this will result in an executable jar .... – khmarbaise Apr 01 '20 at 16:33
  • I can change the classpath of the jar dependencies in the manifest file of my project? –  Apr 01 '20 at 16:53
  • @Croma1994 Why not just build an executable jar as I suggested above and khmarbaise also suggested? – J Fabian Meier Apr 01 '20 at 17:42
  • Oh okay, until now I was doing it manually, exporting the jar to the desired folder and moving the needed dependencies from /target to a /lib folder, then adding the output path to the classpath in manifest file. Maven-assembly-plugin is what I needed. Thanks both of you. –  Apr 02 '20 at 01:34

0 Answers0