download and execute jar file from remote maven repository

the hand of NOD :

That might be a dumb question but somehow I cannot figure it out (even with the lots of already given answers on stackoverflow) how to do it:

  • I created a maven project
  • I called mvn package and can execute the jar file with java -jar ... and everything works fine.
  • After I deploy the jar into the remote repository, I want everyone in my team to be able to just call a maven command (like mvn exec:java or something like that) on the command line and Maven shall download the jar file from the remote repository and execute it.

Independent of the current directory in which the user is. How do I do that? Currently I get the error message that I need to be in a directory with an existing pom.xml file.

    <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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
    </parent>
    <groupId>handof.nod</groupId>
    <artifactId>clirunnertest</artifactId>
    <version>1.0</version>
    <name>CLIRunnerTest</name>
    <description>Kleines Testprogramm um zu testen wie Spring Boot auf der Command Line funktioniert</description>
    <packaging>jar</packaging>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- Package as an executable jar/war -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-jar</argument>
                        <argument>target/clirunnertest-1.0.jar</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Thorbjørn Ravn Andersen :

There is not a single step to do so, and Maven generally wants to be able to use the ~/.m2 folder as a working area. You can however do it in two steps.

  1. Download the artifact directly with dependency:get - see How can I download a specific Maven artifact in one command line? for details.
  2. Then they have the jar file and can start it as usual.

You can also create a pom.xml file for it which the users can download (again as an artifact) and then set it up for mvn exec:java.

If this is something you want to do on a regular basis, I will suggest a regular deployment! Java WebStart works well if you have a webserver somewhere you can store the files.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=461553&siteId=1