Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-19

GUI Designer + Maven: icons imported in the wrong directory

    XMLWordPrintableJSON

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)

      1. File > New Project...
      2. Java | Java application (You could uncheck Create Main Class)
      3. New > JFrame Form...
      4. In the designer drag a JLabel
      5. For the icon property click "..."
      6. Click Import to Project...
      7. Choose an icon then Finish
      8. The icon is copied along the java source file
      9. Run
      10. Everybody happy. It works

      Maven project

      1. File > New Project...
      2. Maven | Java application
      3. New > JFrame Form... (Default values OK)
      4. In the designer drag a JLabel
      5. For the icon property click "..."
      6. Click Import to Project...
      7. Choose an icon then Finish
      8. The icon is copied along the java source file
      9. Run
      10. It crashes with a NullPointerException

      Manual remediation

      1. In the project create src/main/resources
      2. Move the icon to this directory (same package as it was under src/main/java)
      3. NetBeans detects this and adds "Other Sources" to the project tree
      4. mvn clean (to force rebuild)
      5. 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

      Attachments

        Activity

          People

            kosmonaffft Anton V. Kirilchik
            jfelfouly Jean-François El Fouly
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: