26 Şubat 2020 Çarşamba

spring-boot-maven-plugin

Giriş
Açıklaması şöyle
Spring Boot Maven Plugin is a Maven plugin that allows you to package executable jar or war archives and run an application in place. It provides a number of features that are useful when developing Spring Boot applications, such as the ability to package executable jar or war files, run an application in place, and use hot swapping with background compilation to make development faster.

Sunulan goal şunlar
1. repackage
2. run
3. start ve stop
4. build-info
5. build-image

repackage goal  - Fat Jar Oluşturur
Spring boot uygulamasını paketlemek için gerekir.  Açıklaması şöyle.
Unfortunately, if we are working with a jar package, the basic Maven package goal doesn't include any of the external dependencies.

This means that we can use it only as a library in a bigger project.

To circumvent this limitation, we need to leverage the Maven Spring Boot plugin repackage goal to run our jar/war as a stand-alone application.
Maven 3.2 gerektirir. Açıklaması şöyle.
The Spring Boot Maven Plugin provides Spring Boot support in Maven, allowing you to package executable jar or war archives and run an application “in-place”. To use it you must be using Maven 3.2 (or better).
Çalıştırmak için şöyle yaparız
maven package spring-boot:repackage
run Goal 
Debug içindir. Açıklaması şöyle.
By default the application is executed directly from the Maven JVM. If you need to run in a forked process you can use the 'fork' option. Forking will also occur if the 'jvmArguments', 'systemPropertyVariables', 'environmentVariables' or 'agent' options are specified, or if devtools is present.

If you need to specify some JVM arguments (i.e. for debugging purposes), you can use the jvmArguments parameter,...
Normalde spring uygulamasını çalıştırmak için şöyle yaparız. Ancak bu kullanımda pom içinde tanımladığımız jvm parametreleri kullanılmaz.
$ ./myapp-1.1.0.jar --spring.config.name=application-prod
Bu parametreleri de kullanmak için şöyle yaparız.
maven spring-boot:run
Profile seçmek için şöyle yaparız.
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=production"
pom Örnekleri

Örnek - executable jar
Şöyle yaparız
<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <configuration>
        <executable>true</executable>
      </configuration>
    </plugin>
  </plugins>
  <finalName>sba-as-windows-service</finalName>
</build>
Örnek - jvmArguments
Şöyle yaparız.
<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <executable>true</executable>
    <jvmArguments>-Xmx256m</jvmArguments>
  </configuration>
</plugin>
Örnek - jvmArguments
Şöyle yaparız.
<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
      <mainClass>tech.flexpoint.demo.DemoApplication</mainClass>
      <jvmArguments>--show-module-resolution --add-opens=java.base/java.lang=spring.core
        --add-opens=java.base/java.io=tomcat.embed.core
        --add-opens=java.base/java.lang=ALL-UNNAMED 
        --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED</jvmArguments>
      <workingDirectory>${project.basedir}</workingDirectory>
  </configuration>
</plugin>

Hiç yorum yok:

Yorum Gönder