0

I am new to Kotlin and still do not understand everything. I am trying to build a project in .jar but so far without success. I found many many solutions and tried all of them

Invalid signature file digest for Manifest main attributes w/ Jetty and Maven Shade Plugin

"Invalid signature file" when attempting to run a .jar

Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

Valid JAR signature for JavaFX projects

but every time the same error pops up:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

My maven build:

    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>

                <executions>
                    <execution>
                        <id>compile</id>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>test-compile</id>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>io.lavr.utils.any2json.ApplicationKt</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>any2json</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <excludeScope>system</excludeScope>
                            <excludes>META-INF/*.SF</excludes>
                            <excludes>META-INF/*.DSA</excludes>
                            <excludes>META-INF/*.RSA</excludes>
                            <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Please forgive me my ignorance and treat with understanding. Thanks =)

Changes:

assembled jar with such a command:

jar cvmf src/main/kotlin/META-INF/MANIFEST.MF  Application.jar -C target/classes io/lavr/utils/any2json

Then I tried to run:

java -jar Application.jar 

but I have error again:

Error: Unable to initialize main class io.lavr.utils.any2json.ApplicationKt
Caused by: java.lang.NoClassDefFoundError: kotlin/TypeCastException

TonyVol
  • 1
  • 1
  • 1
    Can you list content of built jar using 'jar -xvf' command? Does it have what you are looking for? – VinPro Mar 22 '20 at 03:18
  • I used: `jar -xvf target/any2json-1.0-SNAPSHOT.jar | grep ApplicationKt` Output: `inflated: io/lavr/utils/any2json/ApplicationKt.class inflated: io/lavr/utils/any2json/ApplicationKt$main$1.class inflated: su/m13/lavr/ApplicationKt.class` – TonyVol Mar 23 '20 at 08:06
  • The offending class is `kotlin/TypeCastException` Open this class in your IDE, take not of what jar it belongs to and then check if it's present in your aggregated jar created via maven. – VinPro Mar 28 '20 at 02:01

0 Answers0