2

根据Spring boot 文档,在使用基于 Crash 的远程 shell 时可以定义额外的命令。

这些命令的默认位置是 classpath*:/commands/ ,classpath*:/crash/commands/

属性可用于覆盖默认位置,但在提供的示例中,自定义命令位于资源中。

在我看来,自定义命令(至少是 java 命令)不应位于资源中,而应位于 src/main/java 中。

在资源中定义自定义路径时效果很好,但是如何在 src/main/java 中定义自定义路径?暂时没找到办法!

4

2 回答 2

1

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>
于 2015-08-04T11:59:30.237 回答
-1

你可以尝试把你的命令放在src/main/resources/commands/

于 2015-07-14T09:47:05.397 回答