[英]attach a folder of files into a jar
i am developing a swing application using netbeans 7.1.2 . 我正在使用netbeans 7.1.2开发一个swing应用程序。 In this, i am using some image files.
在此,我正在使用一些图像文件。 The image directory is currently in the dist folder.
图像目录当前位于dist文件夹中。 I want to attach the files with the jar file so that i can carry it anywhere as a SINGLE (jar)file.
我想将文件与jar文件一起附加,以便我可以将其作为单个(jar)文件随身携带。 can anyone please help me with a solution?
谁能帮我解决一个问题?
Assuming your project is Maven-based, I would place the images in the src/main/resources
folder. 假设您的项目基于Maven,我将把图像放在
src/main/resources
文件夹中。 Maven will automatically include the files in that folder into your JAR-file. Maven将自动将该文件夹中的文件包含到您的JAR文件中。
Otherwise, this blogpost will help you out. 否则, 此博客文章将为您提供帮助。
Oi Mate 大井伴侣
First Create a package(Say images) under Source Packages 首先在“源包”下创建一个包(说图片)
copy all of your images to this package(when you create a package,a folder in the name of your package will be created inside your project src folder, so copy images to it) 将所有图像复制到此程序包(创建程序包时,将在项目src文件夹内创建一个以程序包名称命名的文件夹,因此将图像复制到该程序包中)
You can access your Images from your program as 您可以通过以下方式从程序访问图像
URL imageurl = getClass().getResource("/images/imagename");//assuming your package name is images
Image myPicture = Toolkit.getDefaultToolkit().getImage(imageurl);
JLabel piclabel = new JLabel(new ImageIcon( myPicture ));
piclabel.setBounds(0,0,myPicture.getWidth(null),myPicture.getHeight(null));
Now use this JLabel piclabel 现在使用此JLabel piclabel
简单方法:您可以将图像文件夹设置为classpath并通过eclipse导出jar文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.