Вы здесь:

Оглавление:

maven-assembly-plugin

Пример в https://github.com/cherepakhin/camel_spring.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<build>
      <plugins>
...
      <!-- fat jar -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>ru.perm.v.camelinaction.ch2.GreetMain</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.6.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>assemble-all</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
</build>

Сборка:

$ mvn package

Собранный файл будет в ./target/{artifactId+version}-jar-with-dependencies.jar

Запуск:

$ java -jar {jar-file}

 

Другие примеры:

Многомодульный проект Gradle
Дополнительные инструменты для проекта на Kotlin и Spring Boot (Создание запускаемого файла и его запуск)

 

Запуск Spring boot приложения:

Только запуск, без сборки jar и т.п.

Using the Maven plugin

$ export MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=128M
$ mvn spring-boot:run

Using the Gradle plugin
"...The bootRun task is added whenever you import the spring-boot-gradle-plugin..."

$ export JAVA_OPTS=-Xmx1024m -XX:MaxPermSize=128M
$ gradle bootRun


Еще пример из ~/prog/java/camel/camel-examples/java-lambda. Секция build из pom.xml:

    <build>
        <plugins>
            <!-- Allows the example to be run via 'mvn compile camel:run' -->
            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>${camel.version}</version>
                <configuration>
                    <mainClass>org.apache.camel.example.java8.MyApplication</mainClass>
                </configuration>
            </plugin>
            <!-- mvn clean compile exec:java -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <mainClass>org.apache.camel.example.java8.MyApplication</mainClass>
                    <includePluginDependencies>false</includePluginDependencies>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads>
                </configuration>
            </plugin>
            <!-- java -jar target/....jar -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>org.apache.camel.example.java8.MyApplication</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>

Сборка:

./mvnw clean package

Запуск:

/usr/lib/jvm/java-1.17.0-openjdk-amd64/bin/java -jar target/camel-example-java-lambda-4.10.0-jar-with-dependencies.jar

Ссылки: