Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Intellij 13, executable jar created is invalid or corrupted

I tried to create an executable jar from my project on Intellij 13 (win8), following these answers How to build jars from IntelliJ properly? and execute the jar created, then I get "Error: Invaid or corrupt jarfile" followed by the path of the jar.

My project is simple, but have multiple java files and an UI form.

I call Build|Build Artifacts|Jar after create jar artifact on Project Structure|Artifacts, after build.

I created the project with a maven scafold, but there are no dependencies on pom.xml.

I'm using java7. Is something missing?

Artifact

like image 912
Arthur Julião Avatar asked Apr 14 '14 17:04

Arthur Julião


People also ask

Can you debug a jar with IntelliJ?

Debugging in Java is not at all complicated. IntelliJ offers many debugging features for Java developers (e.g. set breakpoints, evaluate expressions). Recently, I had the requirement of debugging a JAR application that required me to pass a connection string argument.


2 Answers

Here is a quick solution WITHOUT pom.xml

I´ve solved it with the artifact settings of IntelliJ by creating a "META-INF" subfolder and copying the Manifest file inside.

I don´t know why this is even needed, but it seems that IntelliJ IDEA doesn´t include the META-INF folder by default

enter image description here

Pointing to the file:

enter image description here

like image 194
Marian Klühspies Avatar answered Sep 21 '22 11:09

Marian Klühspies


Since I couldn't create a jar with the IDEA itself, and I previously create my project with maven scaffold, I decided to use maven to create executable jar. To do it I added to the pom.xml:

<packaging>jar</packaging>
<properties>
    <jdk.version>1.7</jdk.version>
</properties>
<name>Project Name</name>

In build tag:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>main.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

And I also had problems with the UI created by GUI-Designer: NullPointerException in the Pane created. To make it work I added a dependency:

<dependencies>
    <dependency>
        <groupId>com.intellij</groupId>
        <artifactId>forms_rt</artifactId>
        <version>5.0</version>
    </dependency>
</dependencies>

After that, I just used mvn package inside project directory on cmd.

Fonts:

  • How to create a jar file with maven

  • InteliJ idea gui designer + maven

  • IntelliJ IDEA GUI builder – no Java code generated

like image 33
Arthur Julião Avatar answered Sep 21 '22 11:09

Arthur Julião