简体   繁体   中英

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!

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM