在签名 Jar、JNLP 应用程序中加载图像时出错

发布于 2024-10-22 06:44:20 字数 242 浏览 15 评论 0原文

我正在开发 JNLP 应用程序并使用 maven-webstart 插件来创建 JNLP。在本地运行应用程序时,它可以正常工作,但是当我使用 jnlp 在 Tomcat 服务器中运行时,它不会加载图像,也不会给出任何异常。

我正在加载图像,如下所示

new ImageIcon(getClass().getResource("/icons/save.png"))

我的代码有什么问题吗?

I am developing JNLP Application and using maven-webstart plugin to create JNLP. When running the application in my local, it works correctly but when I run in Tomcat Server using jnlp, it does not load images and also does not give any exception.

I am loading images as below

new ImageIcon(getClass().getResource("/icons/save.png"))

What is wrong with my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失眠症患者 2024-10-29 06:44:20

你的图标位于哪里?如何在 tomcat 中运行 jnlp 应用程序?假设您没有很多图像,您可以将它们打包到您的一个包中。只需创建一个名为 com.yourproject.resources 的包并在其中转储一些图像即可。那么访问它们的方法是:
//在某个类中定义它

public URL obtainImageResource ( String nameOfResource )
    {
        return getClass().getResource( "/com/yourproject/resources/" + nameOfResource );
    }

请使用 URL 获取它们。
然后创建您需要的东西:

BufferedImage yourImage = ImageIO.read( yourclaass.obtainImageResource( "yourimagepng.png" ).openStream() );

注意一些事情:在我的设置中,您需要将图像打包到 jar 中。

Where are your icons located? How do you run a jnlp application inside tomcat? Assuming you don't have a lot of images, you can package them inside one of your packages. Just create a package called com.yourproject.resources and dump some images there. Then the way to access them would be:
//define it in some class

public URL obtainImageResource ( String nameOfResource )
    {
        return getClass().getResource( "/com/yourproject/resources/" + nameOfResource );
    }

Do get them with a URL.
Then to create the stuff you need:

BufferedImage yourImage = ImageIO.read( yourclaass.obtainImageResource( "yourimagepng.png" ).openStream() );

Note some things: In my setup you need to package your images into your jar.

墨离汐 2024-10-29 06:44:20

如果没有更多信息,很难说。您可以使用 jar -tf 来查看图像是否在 JAR 文件中。同时,这里有一个可以加载图像的 JWS 应用程序,供参考。

It's hard to say without more information. You might use jar -tf to see if the images are in the JAR file. In the meantime, here's a working JWS application that loads images, for reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文