简体   繁体   中英

Spring boot additional Crash Command

According to the Spring boot documentation , it's possible to define additional command when using a remote shell based on Crash.

Default locations for these commands are classpath*:/commands/ ,classpath*:/crash/commands/

A property can be used to override the default locations but in the provided example, the custom command is located in resources.

In my opinion, custom commands (at least java commands) shouldn't be located in resources but in src/main/java.

It works fine when defining a custom path in resources but how can I define a custom path in src/main/java? Didn't find a way to do it for now!

If they're under src/main/java , they'll be compiled automatically which is not what you need. My solution was to simulate that directory as a resources folder, which in short translates to:

  1. configure the compiler plugin to ignore that particular folder
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
            <source>${java.version}</source>
            <target>${java.version}</target>
            <excludes>
                <exclude>crash/commands/*</exclude>
            </excludes>
        </configuration>
    </plugin>
  1. copy the files just like any regular resources in the target directory
    <resource>
        <directory>src/main/java/crash/commands</directory>
        <targetPath>crash/commands</targetPath>
        <filtering>false</filtering>
    </resource>

Minor update & disclaimer:

As you may already know, there are a couple of closures which are executed on login/logout. At least with v1.3.1, which is what I'm blindly inheriting from spring-boot, it will pick the first login.groovy it finds in the classpath. My project's artifact is packaged in an RPM along with all the other dependencies. Since its name begins with r , it comes after crash.shell-1.3.1.jar which is where the defaults reside, so I had to do the following small hack to make it pick up my own scripts instead of the default ones:

<!-- hack to make CRaSH pick up login.groovy from our jar instead of the default one -->
<finalName>0_${project.artifactId}-${project.version}</finalName>

您可以尝试将命令放在src/main/resources/commands/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM