Search code examples
javamavenjarmaven-assembly-plugin

Cannot open jar created by maven assembly plugin


When i create jar with maven-assembly plugin it compiles correctly but when i try to open jar it gives me that error All components are initialized by my IDE:

Exception in thread "main" java.lang.NullPointerException
at App.<init>(App.java:26)
at App.main(App.java:149)

App.java link to code. https://pastebin.com/DPNBGadn

Code is correct because when i open it by intellij idea it works correctly.

build tag:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>App</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>


Solution

  • The problem is not in how your jar was created, but in code of the App class. You should initialize your private JButton loginButton; before calling addActionListene method on it.