How to deploy resources with guice

I have a class that is introduced using guice, and this constructor class calls super, with the resource loaded by the .getResource (..) class

@SuppressWarnings("serial")
public class CleanAction extends AbstractAction {

    private final JTable table;
    private final PowderTableModel tableModel;

    @Inject
    public CleanAction(@Named("data") JTable table, PowderTableModel tableModel) {
        super("Clean", new ImageIcon(CleanAction.class.getResource("/icons/table.png")));
        this.table = table;
        this.tableModel = tableModel;
    }

...
}

It works fine in tests, but when guice initializes, the result of CleanAction.class.getResource ("icons / table.png") is null, so it does not work with NullPointerException.

Is there any way to engage in resources?

+3
source share
2 answers

To answer your question: “Is there any way to engage in resources?”, I would say “no, not out of the box.”

, ResourceInjector , Guice, Guts-GUI framework (Apache License 2.0). , Guice, , Guice.

, , ( "resources" JLabel, JButton...)

, , - ( ...)

+2

? , classpath . classpath . classpath , , .

maven? , src/test/resources, src/main/resources?

+1

Source: https://habr.com/ru/post/1763757/


All Articles