I am trying to export my java project to an executable file (a .jar) but it wont bring along the assets with it(such as pictures and things). I am programming with Eclipse. I have looked at other forums about this and try their fixes but it doesn't seem to work for me. I think the problem has something to do with where i put my .gif and .wav. I put them in the same folder as the src folder with my .java files. Here is my code. Thanks for the help!
class ImagePaneTest extends JFrame
{
ImageIcon ic = new ImageIcon("scary.gif");
JDesktopPane dp = new JDesktopPane();
JLabel lbl = new JLabel(ic);
JPanel transparentPanel = new JPanel();
public ImagePaneTest()
{
lbl.setBounds(0, 0, 553, 421);
dp.add(lbl,new Integer(50));
dp.add(transparentPanel,new Integer(350));
setLayeredPane(dp);
}
public static void main(String a[])
{
try {
Thread.sleep(8000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
ImagePaneTest fr = new ImagePaneTest();
Image icon = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
fr.setIconImage(icon);
fr.setSize(553,421);
fr.setVisible(true);
fr.toFront();
fr.setLocation(370, 200);
sound play = new sound();
play.playSound("wail.wav");
System.exit(0);
}
}
You need to specify it from . (dot)
Let's suppose this class
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
class ImagePaneTest extends JFrame
{
ImageIcon ic = new ImageIcon("./images/nice.jpg");
JDesktopPane dp = new JDesktopPane();
JLabel lbl = new JLabel(ic);
JPanel transparentPanel = new JPanel();
public ImagePaneTest()
{
lbl.setBounds(0, 0, 553, 421);
dp.add(lbl, new Integer(50));
dp.add(transparentPanel, new Integer(350));
setLayeredPane(dp);
}
public static void main(String a[])
{
ImagePaneTest fr = new ImagePaneTest();
Image icon = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
fr.setIconImage(icon);
fr.setSize(553, 421);
fr.setVisible(true);
fr.toFront();
fr.setLocation(370, 200);
}
}
then you export to jar (not runnable jar) using the default options, except for the main class
then
java -jar my.jar
and voilà