在 Maven 中为 SikuliX 打包图像

Packing images for SikuliX in Maven

我正在编写一个使用 SikuliX 的应用程序,但我在从我的代码生成 jar 时遇到问题。

我将用于我的代码的图像存储在 src/main/resources 中,我正在使用我的 pom.xml

中的代码构建 jar
<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.dustinroepsch.leadtimetool.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

当我用 7-zip 打开创建的 JAR 时,我可以看到我的图像被添加到 jar 的根目录中。我想这就是我想要的,但我不确定。

我通过

在我的代码中引用图像
Screen s = new Screen();
ImagePath.add("src/main/resources");
s.hover("1462980188453.png");

当我通过 Netbeans "play" 按钮启动我的代码时,它 运行 很棒。

但是,当我从命令行 运行 带有依赖项的 jar 时,我得到了错误

FindFailed: Region: doFind: Image not loadable: 1462980188453.png

图像打包在罐子里,罐子里有sikuli依赖。是否有我要添加的图像路径,以便我的可执行 jar 能够正确找到图像?

谢谢!

我想出了一个很好的解决办法

Maven 会自动将资源目录中的所有内容打包到 jar 的根目录中。

您应该做的是在您的资源目录中创建一个名为 "images"(或任何名称)的文件夹,并将您的文件夹放入其中。

那么你可以使用ImagePath.add("com.yourcompany.yourpackage.AnyClass/images");

一切都会按预期进行