如何导出工作jar与非jar依赖 [英] How to export working jar with non-jar dependencies

查看:210
本文介绍了如何导出工作jar与非jar依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相当新的java和im做一个pokemon风格的游戏练习,我想能够发送给我的朋友的游戏。



这里是主要的问题:游戏在我的netbeans IDE中工作正常,但是在我的dist文件夹中使用jar文件不起作用,并抛出一个nullPointerException。我缩小了这个问题。我的游戏使用我在我的图书馆导入的imageIcons和png / gif图像。我们可以像这样访问他们

 图标bckground = new javax.swing.ImageIcon(getClass()。getResource(/ pictures /BG.gif)); 

我不确定如何将图像放入lib文件夹中以供程序查找。我已经尝试将文件直接复制到lib文件夹,并为他们创建一个名为图片的文件夹;没有工作。现在lib文件夹只包含一个其他库中的一个jar。 (这是我导入到我的图书馆的唯一jar文件)



在IDE中看起来像的图片

解决方案

在我的情况下,我做了这样的东西。

  final BufferedImage image = ImageIO.read(new File(something.jpg)); 

我刚刚将something.jpg转移到dist文件夹中,并且工作正常。



清理构建项目后,将BG.gif放入dist文件夹,然后在dist文件夹中运行您的jar文件。现在一切都应该好当您将游戏发送给您的朋友时,您可以封装(隐藏,设置只读)您的代码(google encultaion java),然后将BG.gif转移到dist文件夹中,归档项目。那么你的朋友只需要解压缩并在dist文件夹中找到jar文件。



希望这将有助于:)


im fairly new to java and im making a pokemon style game for practice and i would like to be able to send the game to my friends.

here is the main problem: the game works fine in my netbeans IDE, but using the jar file in my dist folder does not work and throws a nullPointerException. i have narrowed down the problem. my game uses imageIcons and png/gif images that i have imported in my libraries. im getting access to them like this

Icon bckground = new javax.swing.ImageIcon(getClass().getResource("/pictures/BG.gif"));

i am unsure how to get the images into the lib folder for the program to find. i have tried copying the files straight into the lib folder and creating a folder for them called pictures; neither worked. right now the lib folder contains only a single jar from one of my other libraries. (that is the only jar file that i am importing to my libraries)

Pic of what it looks like in IDE

解决方案

In my case, i did something like this.

final BufferedImage image = ImageIO.read(new File("something.jpg"));

I just transferred something.jpg into the dist folder, and it worked fine.

After clean-building your project, put the BG.gif into the dist folder, then run your jar file in dist folder. Now everything should be fine. When sending your game to your friends, you can encapsulte (hide, set read-only) your code (google encapsultaion java), then with the BG.gif being transferred into dist folder, archive the project. Then your friends only need to unzip it and find jar file in dist folder.

Hope this will help:)

这篇关于如何导出工作jar与非jar依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆