Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
8.2, 9.0
-
None
-
None
-
Windows 7 Professional
JDK 1.8.0_111-b14
Maven 3.3.3
Description
An annoying and tricky little bug.
Nominal scenario (NetBeans non-Maven project)
- File > New Project...
- Java | Java application (You could uncheck Create Main Class)
- New > JFrame Form...
- In the designer drag a JLabel
- For the icon property click "..."
- Click Import to Project...
- Choose an icon then Finish
- The icon is copied along the java source file
- Run
- Everybody happy. It works
Maven project
- File > New Project...
- Maven | Java application
- New > JFrame Form... (Default values OK)
- In the designer drag a JLabel
- For the icon property click "..."
- Click Import to Project...
- Choose an icon then Finish
- The icon is copied along the java source file
- Run
- It crashes with a NullPointerException
Manual remediation
- In the project create src/main/resources
- Move the icon to this directory (same package as it was under src/main/java)
- NetBeans detects this and adds "Other Sources" to the project tree
- mvn clean (to force rebuild)
- Now it works
Rationale
Importing an icon and associating to a JLabel generates code such as this:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/test/mavenproject1/bookmark.png"))); // NOI18N
But the maven compiler plugin will not copy the icon to target/classes so target/classes contains the classes but not the image. So the code above causes a NPE.
Bottom line
In a Maven project icons should not be imported to src/main/java but to src/main/resources, same package.
This small but annoying bug is not a regression: it can easily be reproduced in 8.2