How do I specify resource files (images, sounds) to be added to the JAR build?

Goal: Resources include things like images, sound files, property files. The target JAR file should have all the resources in "res" folder.

Solution: For instance you would like to use specific resources for Nokia Series 40, 60 and Motorola M1. Create following directory structure:


Put resource files in specific folders, i. e.

Then open project customizer (right click on the Project > Properties) and add the directory with resources in Libraries & Resources (Add Folder). All content of the folder gets added into the JAR file. You may use different folders in different configurations.

Then reference the resources:

ImageIcon logoN60 = new ImageIcon(this.getClass().getResource("res/Nokia60/logo.ping"));

NOTE: getResource() returns a URL path to the location of the resource within the JAR, which can then be passed to ImageIcon or some other method that will use the URL. The path to the file is relative to the class in which this code resides.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo