score:0
in eclipse: you can place image files along with java source code files, if you are putting it in other directory then make sure you create that directory as src directory. and create packages same as source code packages, and copy image files to those created packages.
for example:
src (source directory)
^-------------------com.myproject
^................ main.java
resource (source directory)
^-------------------com.myproject
^................ logo.png
then try to export this project as jar file.
score:0
you need to put your images inside of a source folder and ensure that the settings for that folder don't exclude what you are trying to export.
try setting up a clean java project to ensure that it all works as expected with your version of eclipse to see what may be missing. create a new project following these instructions using the project dialog:
file
>new
>java project
- in the first dialogue step
project layout
>configure default...
change the source folder name tosrc/main/java
which is the convention followed by tools like gradle and maven so it is the project layout for most opensource projects so its a good convention to stick with. - second dialogue step
create new source folder
give it the namesrc/main/resources
which is again the standard naming.
create the new project and drag-drop an image into src/main/resources
e.g. test.jpg
then add a java class:
public class test {
public static void main(string[] args) throws exception {
system.out.println(test.class.getclassloader().getresourceasstream("test.jpg").available());
}
}
run it in eclipse to check it gives you the image file size. then do file
> export
> jar file
and export it to /tmp/test.jar
and run it with java -cp /tmp/test.jar
to see that it gives you the output.
that all works for me. go back through that project settings and compare it with the one you are trying to setup. note that there are options to include/exclude files which get exported by filename so it may be the case what you have an export filter which is stopping your files being exported. my recommendation is that you put all code under src/main/java
and all resources such as images and config files under src/main/resources
then have no export filters which is how build tools such as maven and gradle do things.
score:1
maven is my suggestion
if you're following the standard maven project directory structure then it is best to put all non-java resources under src/main/resources. for example, you could create a subdirectory images, so that the full path would be src/main/resources/images. this directory would contain all your application images.
a special care should be taken to properly access images when application is packaged. for example, the following function should do everything you need.
public static image getimage(final string pathandfilename) {
final url url = thread.currentthread().getcontextclassloader().getresource(pathandfilename);
return toolkit.getdefaulttoolkit().getimage(url);
}
this function can be used as getimage("images/some-image.png") in order to load some-image.png file in the image directory.
if imageicon is required then simply calling new imageicon(getimage("images/some-image.png")) would do the trick.
Source: stackoverflow.com
Related Query
- How to export java project from eclipse into a jar file with images
- How to Export Java Project in Eclipse with Image Library as a jar file
- How to deploy an Eclipse java project into a jar file
- How to create a jar file from an eclipse java project that uses *.jar files added in "Classpath"
- Export Java project from Eclipse as JAR with additional referenced jars
- How can I export jar file from Eclipse with the referenced libraries?
- How export an Eclipse project including IBM classes for Java libraries into an executable JAR
- How to add a jar file to an eclipse java project from command line?
- How can I make Eclipse export 1 JAR file per project to a specific directory with as few clicks as possible?
- How to create Jar file from Maven project in eclipse
- How to export an Eclipse Project with External Jar dependencies?
- How to recover Java file from Eclipse Project that damaged by getting power off?
- How to create runnable jar with resources in Eclipse from Maven project
- How to include the jars referenced in "Java Build Path" section of an Eclipse project in a jar file generated with Ant using a build.xml file
- How to make the runnable jar file for a maven eclipse project with hibernate configuration
- How to read a property file of a project from another java project in eclipse
- How to read a java file from Eclipse into Mathematica
- How can I export a runnable jar in Eclipse with a specific manifest file and required library extraction?
- Build Spring Roo / Export maven project with Eclipse Export -> Runnable JAR file
- How To Embed JAR Library into Project with Eclipse
- How do I make a (minimal) runnable jar file from a scala eclipse project
- How to convert a java project into .exe file in eclipse
- How to execute or implement batch file in java project with eclipse
- Exporting java project to runnable jar file with images
- Cannot export default Java libGDX project as a jar from Eclipse
- Java project turned into runnable jar in Eclipse --- file too big
- how to update a external jar with my java class file on eclipse
- how to export jar file contains .class with eclipse
- How to access a text file from a java EXPORTED project eclipse
- How to import a project into eclipse downloaded from developer.android.com zip file
More Query from same tag
- Deploy and debug application on OC4J in eclipse
- In-place ("Quick-Assist" or something easier) source code modifier?
- switch-case in Java 1.8 with Eclipse not possible?
- Trouble importing Spring Boot Gradle project into Eclipse
- How to handle Maven WAR overlays in Eclipse?
- Android thread exiting with uncaught exception (group=0x4000fe70) Error
- Interface builder in Eclipse for Android: how to see my activity in fullscreen?
- How to specify trigger key for content assit in Eclipse RCP editor?
- Is it possible to generate the artifact.xml and content.xml without using tycho plugin
- copy content from one file to another in java with extra spaces between characters
- The application is installed but not running or visible on virtual device
- How to open a second package-explorer window in Eclipse?
- How can i use getResource(...) to grab the .png file from resources
- Eclipse PHP Can't connect to SQL using XAMPP
- Generics: Type argument is not within its bounds
- Import CSVReader in java
- Debugging java source file with multiple classes in eclipse: Source not found
- Better way to add the dependency projects to the classpath?
- developing Android on Eclipse
- How do I find the jsp file which runs first when starting a spring project via web.xml?
- Eclipse History Load When Opening Source File
- Need Lucene 4.1.0 source jars or javadoc jars (to make developing with Lucene 4.1.0 in Eclipse usable)
- How to add an Icon to an application built with Eclipse Galileo C and MinGW?
- Is it possible to force Eclipse to recompile my files every time I try to run JUnit tests?
- Failed to export application Command-line Error -1073741819 after updating Eclipse to 23.0.5 and SDK to 5.0
- Implicit super constructor Seat() is undefined. Must explicitly invoke another constructor
- Duplicate Eclipse workspace with projects
- perl.exe runs from any folder, and perldoc.bat is not. Meanwhile they both are located in the same folder
- Error Undefined Procedure in Prolog while using (condition -> then_clause ; else_clause)
- How to install the Perforce plugin in Eclipse 4.2