【发布时间】:2021-05-25 09:50:25
【问题描述】:
试图让 SplashScreen 在 Java 中工作;不幸的是没有任何成功。 我已经阅读了很多关于它的主题,但几乎所有主题都已经很老了。
我已经建立了一个 maven 项目,并且正在关注关于 SplashScreen 的 Sun/Oracle 教程。 我正在使用 maven-jar-plugin 创建 manifest.mf 文件。在那里我指定了主类和图像文件,如教程中所示。
我的 pom.xml 文件的提取
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
我的 manifest.mf 文件包含以下两行:
Main-Class: com.mycompany.splashscreen.MySplashScreen
SplashScreen-Image: images/java-duke-logo.jpg
我复制了src/main/resources/images中的图片,遵循了maven标准目录推荐。
不过,下面这行:
final SplashScreen splash = SplashScreen.getSplashScreen();
总是返回 null!
在生成的 jar 文件中,图像被放入包“images”中。
请寻求线索以使其发挥作用。谢谢。
(我的工作环境:MacOSX 10.13.6、jdk16、NetBeans 12.3)
【问题讨论】:
-
那个SplashScreen类的代码怎么样?
-
不,它不能。而且,如您所见,他们清楚地表明,在该示例中,它可以为 null
-
方法调用返回null应该是有原因的,但我想不通。