DJ MERKEL
DJ MERKEL

Reputation: 87

IntelliJ: Maven: Build Artifact to Jar but cant execute jar

I've set up a project with mavens standard directory structure:

App: --> src -->main -->java -->com -->company -->appname -->//Here the classes

I Also have a META-INF-directory under the java directory with a MANIFEST.MF:

 Manifest-Version: 1.0
 Main-Class: com.company.appname.MyMain

My maven pom.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0     http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dsds.cryptoapp</groupId>
<artifactId>Crytpo</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>com.jgoodies</groupId>
        <artifactId>jgoodies-forms</artifactId>
        <version>1.9.0</version>
    </dependency>
</dependencies>

As you can see i import the JGoodiesLibrary as dependency for the project.

Everything normal so far.

Now i build an artifact in IntelliJ via Maven by clean --> compile --> package --> install.

The jar is created, but my library is missing. Also when i start the jar via windows cmd with "java -jar myapp.jar" it says that my mainmanifestattribute is missing even thought it is there!

Upvotes: 2

Views: 1151

Answers (2)

Nat
Nat

Reputation: 899

have you verified the libraries that are not included are added to the package in the project? you can go to Project Structure (Alt Ctrl Shift S), Artifacts in Output Layout, add the libraries you need in the final package.

Upvotes: 1

Kiryl
Kiryl

Reputation: 111

Jar plugin can generate a manifest for you, I'd suggest to use it this way: https://maven.apache.org/shared/maven-archiver/examples/classpath.html#Make_The_Jar_Executable

I guess you have to add classpath into manifest file as well: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Upvotes: 2

Related Questions