我正在编写一个使用SikuliX的应用程序,我在使用代码生成jar时遇到问题。
我将代码中使用的图像存储在pom.xml
中,我正在<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>
Screen s = new Screen();
ImagePath.add("src/main/resources");
s.hover("1462980188453.png");
当我用7-zip打开创建的JAR时,我可以看到我的图像被添加到jar的根目录中。我想这就是我想要的,但我不确定。
我通过
引用我的代码中的图像FindFailed: Region: doFind: Image not loadable: 1462980188453.png
当我通过Netbeans“播放”按钮启动我的代码时,它运行得很好。
但是,当我从命令行运行带有依赖项的jar时,我收到错误
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 521.92 138"><defs><style>.a{fill:#0e0e0e;}.b{fill:#535353;}</style></defs><title>macys_john</title>
<path class="a" d="M319.2,48.7a42.9,42.9,0,1,0,0,31.6v24.4h3.1V23.6h-3.1V48.7Zm-11.7,44a39.83,39.83,0,1,1,11.7-28.2A40.26,40.26,0,0,1,307.5,92.7Z"/>
<path class="a" d="M200.2,21.5c-12.2,0-20.3,5.6-25.1,12.3a37.57,37.57,0,0,0-4.7,9.1,29.89,29.89,0,0,0-5.2-10.4c-4.7-6.2-12.7-11-24.8-11s-20.3,5.6-25.1,12.3a40.48,40.48,0,0,0-3.6,6.3V23.6h-3.1v81.2h3.1V53.4a33.76,33.76,0,0,1,6.1-17.8c4.4-6.1,11.4-11,22.6-11s18.1,4.4,22.3,9.8a28.9,28.9,0,0,1,5.7,16.8v53.9h3.1V52.3a33.39,33.39,0,0,1,6-16.6c4.4-6.1,11.4-11,22.6-11s18.1,4.4,22.3,9.8a28.9,28.9,0,0,1,5.7,16.8v53.9h3.1V51.3a31.4,31.4,0,0,0-6.4-18.7C220.3,26.3,212.3,21.4,200.2,21.5Z"/>
<polygon class="a" points="476.4 23.4 473 23.4 439.7 100.6 408.3 23.4 405 23.4 438 104.6 423.6 138 427 138 476.4 23.4"/>
<path class="a" d="M518.6,70.6c-3.3-4.5-9.3-7.8-20.3-10.7-9.1-2.4-13.6-6.1-16-9.4a12,12,0,0,1-2.6-7.1V43h0V41.9a19.9,19.9,0,0,1,2.7-10.1c2.4-3.8,6.7-7.2,15.6-7.3,9.4,0,13.8,3.6,16.3,7.5a18.22,18.22,0,0,1,2.6,9.5v0.3L520,42V41.5a21.87,21.87,0,0,0-3.1-11.1c-2.9-4.7-8.7-9-18.9-9-9.7,0-15.4,4.1-18.3,8.7a22.79,22.79,0,0,0-3.2,11.8v1.4a15.17,15.17,0,0,0,3.2,9c2.8,3.9,8.1,8,17.7,10.5,10.8,2.9,16.1,6,18.6,9.6s2.9,7.9,2.8,14a17,17,0,0,1-6,12.5,22.32,22.32,0,0,1-15,5.6,23,23,0,0,1-14.3-5.1c-4.1-3.4-6.9-8.6-6.9-16h-3.1c0,8.2,3.3,14.4,8.1,18.4a25.27,25.27,0,0,0,16.3,5.8c13.4,0,24-9.9,24-21.1C522,80.4,521.9,75.2,518.6,70.6Z"/>
<polygon class="b" points="56.6 52.5 45.8 19.3 35 52.5 0 52.5 28.3 73.1 17.5 106.3 45.8 85.8 74 106.3 63.2 73.1 91.5 52.5 56.6 52.5"/>
<polygon class="a" points="475.4 16.1 480.6 12.3 485.9 16.1 483.9 10 489.1 6.2 482.6 6.2 480.6 0 478.6 6.2 472.2 6.2 477.4 10 475.4 16.1"/>
<path class="a" d="M368.7,24.7a39.84,39.84,0,0,1,28.2,11.7,38.91,38.91,0,0,1,8.6,12.9h3.3a42.93,42.93,0,1,0-.1,30.8h-3.3A39.9,39.9,0,1,1,368.7,24.7Z"/></svg>
图像被装在罐子里,罐子里面有sikuli依赖。是否有一个图像路径供我添加,这样我的可执行jar会正确找到图像?
谢谢!
答案 0 :(得分:0)
我找到了一个很好的解决方案。
Maven会自动将资源目录中的所有内容打包到jar的根目录中。
您应该在资源目录中创建一个名为“images”(或任何内容)的文件夹,并将文件夹放在其中。
然后您可以使用ImagePath.add("com.yourcompany.yourpackage.AnyClass/images");
事情将按预期发挥作用