Вопрос

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

Это было полезно?

Решение 2

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:

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top