score:0
The problem was I had this project in my Windows profile... that had an "!" in it... (DeNitE! -> was the name of my Windows profile)
As soon as I changed it to DeNitE (without the !) it worked fine...
score:0
Another work around is if you put your resource file, an your .jar file in the same location, it should work. The only drawback is you have to have the resources with the jar file at all times.
If that's not an issue you can do it this way.
score:1
For creating a runnable JAR file from Eclipse we may refer to the article "Creating Runnable Jars in Eclipse (or other IDE...or by hand):" (https://www.cefns.nau.edu/~edo/Classes/CS477_WWW/Docs/RunnableJarsinEclipse.html), it mentioned that we need do four things as
- Make sure create a package for our code, not just create a project in Eclipse
- Create the sub-pakage (subfolder) for our resource files under the main package of our code (note that the sub-package is under main package, is not only in the project)
- get all file references from getResource() (getting the URL reference)
- Export of files as a runnable JAR in Eclipse (File -> Export... -> select Runnable JAR files -> next -> ...)
But for image file in the example code of above article it only creates the ImageIcon, it does not create the SWT Image, and there are many questions in the Internet for how to get SWT Image from URL or how to convert ImageIcon to SWT Image, below is the example code for getting the SWT Image from URL,
Image imgSWT=null; // Image class is the SWT Image class
ImageDescriptor imgDesc=null;
java.net.URL imgURL = YourClassName.class.getResource("path/image_filename");
if (imgURL != null) {
imgDesc = ImageDescriptor.createFromURL(imgURL);
imgSWT = imgDesc.createImage();
}
score:1
Unless you have to have you files in the jar, this is probably the simplest way of doing it:
header = ImageIO.read(new File("./resources/header.jpeg"));
header has to be an Image/BufferedImage. This goes to the folder that the runnable jar is within and looks for a folder called resources. http://i.stack.imgur.com/x8xtO.png
score:1
Two Simple steps:
1 - Add the folder to Build Path;
2 - Use this:
InputStream url = this.getClass().getResourceAsStream("/load04.gif");
myImageView.setImage(new Image(url));
score:1
I have same issue.. You can use this..
Image Icon= new ImageIcon(new WE4().getClass().getResource("IC.jpg"))
Here WE4 is my class constructor name. Hope it helps.
score:2
score:88
Works fine for me. Check what you may have different.
Example 1: (resources in src)
Steps:
File Structure
Code
package com.stackoverflow.test; import java.net.URL; import javax.swing.*; // Wild carded for brevity. // Actual code imports single classes public class Main { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run() { URL url = Main.class.getResource( "/resources/stackoverflow.png"); ImageIcon icon = new ImageIcon(url); JFrame frame = new JFrame(); frame.add(new JLabel(icon)); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } }
[Right click on project] → [Export] → [Runnable Jar File] → [Set up Launch config]
Profit
FYI, the same setup runs in eclipse just fine also
Example 2: (resources not in src - but in project)
Steps:
File Structure (notice resources looks like a plain folder)
What we have to do now, is put the resources on the build path. What this does is put everything in the folder (excluding the folder itself) on the classpath
Right click on the project and go to [Build Path] → [Configure Build Path]
From the [Sources] tab in the dialog, select [Add Folder] and in the new dialog, select the [resources] folder
Now the contents of the resources folder is in the build path (notice the little package in the folder now
New code no longer uses the resources prefix for the path
URL url = Main.class.getResource("/stackoverflow.png");
Same as Step 3 and 4 from above, and profit!
UPDATE
Setting up Launch Configuration
Generally, once you run the class (i.e. Right click on class and Run as Java Application), a run configuration will be set up. You will need this to set as the launching point in the manifest. But here's how to do it manually.
Steps:
[Right Click Project] → [Properties] → [Run/Debug Settings]
You can see that I already have a run configruation (that is implicitly set from simply running the class). But to create a new one, select [New] → [Java Application]
Create a name for run configuration and browse or type an main launching class. In my case its the
com.stackoverflow.test.Main
classNow when you export as shown in the above example, you select the run configuration
Run the jar like above.
EDIT
Result to Check for
Manifest:
Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Rsrc-Main-Class: com.stackoverflow.test.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Extracted jar:
Source: stackoverflow.com
Related Query
- Eclipse exported Runnable JAR not showing images
- Java project working on Eclipse but not working when exported to runnable jar file
- Eclipse IvyDE managed libraries not exported into runnable JAR file
- Java - program works perfectly in eclipse but does not seem to do its intended task when exported to runnable jar
- Runnable exported JAR not running as it should when out of Eclipse
- Gradle dependencies not being exported to runnable jar by eclipse
- Program runs completely in Eclipse but does not run when exported as a Runnable JAR file
- Jar file with packaged images exported from Eclipse not running
- "Could not find the main class" error when running jar exported by Eclipse
- Exported runnable JAR file from Eclipse doesn't seem to execute
- Why doesn't a runnable JAR exported from Eclipse work?
- Eclipse not showing classes from an external JAR file
- Program runs in Eclipse, but exported runnable jar file will not open?
- Won't open runnable jar exported from eclipse Mac OS
- Buffered Images not rendering when project is built as an executable jar file in eclipse
- Images not loaded when exporting to runnable jar
- Exporting runnable JAR file does not support UTF-8 encoding - Java Eclipse
- Exporting an Eclipse Project into a Runnable Jar does not work
- Eclipse exported Runnable Jar fails througing java.lang.UnsatisfiedLinkError exception
- Exported JAR file does not show images
- Eclipse export to a runnable JAR - Class files on classpath not found or not accessible for :
- Eclipse jar file is not exported with project
- Not able to create runnable jar for eclipse project
- Eclipse not showing images in JavaDoc view
- Compiling java file at runtime works on eclipse but doesn't work from an exported runnable jar file
- eclipse - export runnable jar file not working, running works
- Reading a .txt file into JAR. It works in Eclipse but not in exported JAR
- Images not shown while running the JAR created by Eclipse
- Jar runnable eclipse not working
- I exported a runnable jar using eclipse of my javafx14 application but cannot run the application
More Query from same tag
- Liferay developer client webservices
- Where to find eclipse source that was in cvs or is in subversion?
- How do I write a boolean remove method for an OrderedList class
- Trying to merge two JSONobjects in android
- Uploading file to local Eclipse folder
- Eclipse javadoc: The type package-info is already defined
- Unable to install glass sample using adb on MAC
- Connecting DB2 Express-C in java using Eclipse Indigo
- Want to develop a WYSIWYG editor for GUI in eclipse
- Unable to create Android Virtual Device in eclipse, (Ok button is clicked but no action performed)
- Eclipse know where a project is linked
- Java Eclipse Software Update Problem
- Installed plugin not listed in Plug-in selection
- Servlet cannot find the file I'm trying to open
- Android studio : java.lang.NoClassDefFoundError
- org.apache.wicket.markup.html.WebPage option not appearing when i try to extend WebPage
- Eclipse - Kotlin
- Running unit-tests using PyDev
- generate java domain objects from database table
- How do I use LibGDX, Gradle, Git, and Eclipse together?
- How do i use a bunch of .h and .cpp files to create a static library that can be used in another c++ Project
- Tree compare revision in Eclipse SVN
- Eclipse/Subversive: Startup Guide
- XDoclet, a dead tool?
- Vertical line between matching curly braces for java in eclipse
- How to include third party jars while running a java program
- Is there a way to add a Horizontal Scroll bar on a layout with a tablelayout?
- Eclipse Luna 1.7 to 1.8 errors
- Java .Jar Image Not Showing Up
- How to deploy an ear file in jboss using Eclipse?