I have an image I downloaded for a browse button. I put it in my src/main/resources folder in my maven project. In my Browse Action here is my code for the class:
package net.draconia.testcopier.ui.actions; import java.awt.event.ActionEvent; import java.net.URL; import javax.swing.AbstractAction; import javax.swing.ImageIcon; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; import net.draconia.testcopier.TestCopierController; @Component public class Browse extends AbstractAction { private static final long serialVersionUID = 6237458116383473511L; private TestCopierController mObjController; public Browse(final TestCopierController objController) { super(); URL objURL = Browse.class.getResource("./if_8_27829.png"); putValue(SMALL_ICON, new ImageIcon(objURL)); setController(objController); } public void actionPerformed(final ActionEvent objActionEvent) { getController().browseForBackupFolder(); } protected TestCopierController getController() { return(mObjController); } protected void setController(final TestCopierController objController) { mObjController = objController; } } The problem is though I get a null in the constructor when I try to access the image through Browse.class.getResource(...). I've tried with "./" before the filename and without it there - just bare filename too and I get the same result. Here is my pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>net.draconia</groupId> <artifactId>reedelseviertestcopier</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Reed Elsevier Test Copier</name> <properties> spring.version>4.3.2.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> <resources> <resource> <directory>${basedir}/src/main/resources</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> </build> </project> I don't know if maybe the error is in my pom file why in eclipse I can't get it to see the image. I was about to try to implement my project to produce an executable jar so I can try running it in a command line to produce the output window and such but figured it should at least work in eclipse, you know? Any thoughts?