0

What I am trying to do is make a jar file and run it. I have a maven project whose 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>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>hola.test</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-hive_2.11</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160810</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>5.5.0</version>
        </dependency>
    </dependencies>
    </project>

and my manifest

Manifest-Version: 1.0
Main-Class: hola.test

I have my jar file under projectroot/out/artifacts/test_jar/test.jar and my manifest under projectroot/main/resources/meta-inf/manifest.mf

As stated my some questions like this one. I created out folder myself then built my artifact, but no help.I don't remember facing this problem while working with Netbeans. Is this Intelij bug or something? or am I missing some points ? This is the error output

/usr/lib/jvm/java-1.8.0-openjdk-i386/bin/java -Dfile.encoding=UTF-8 -jar /home/saurab/sparkProjects/test/out/artifacts/test_jar/test.jar
Error: Could not find or load main class hola.test

Steps I took to create jar file 1) go to project structure 2) artifact > hit[+] > jar > from modules with dependencies >select main class[in my case is test] & change manifest folder from main/java to main/resources > hit[OK] > hit [OK]

Saurab
  • 1,931
  • 5
  • 20
  • 33
  • Are there any digital signatures in the artifact? See https://stackoverflow.com/a/45169655/104891. – CrazyCoder Jul 20 '17 at 16:12
  • @CrazyCoder sorry I am lost with digital signature, but I followed (https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000120864--SOLVED-How-to-turn-a-mixed-Kotlin-Java-project-with-a-Kotlin-file-as-main-class-into-a-JAR-?page=1#community_comment_115000144030) this , still getting same error – Saurab Jul 20 '17 at 16:50
  • So, you will need to provide the [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) to get help. – CrazyCoder Jul 20 '17 at 16:50
  • my test class includes System.Out.println("hola") inside main function and I gave the pom file. That's ll it's needed to reproduce my problem :) – Saurab Jul 20 '17 at 16:54
  • Yeah, but if you zip and share the project directory, you will save others a lot of time. – CrazyCoder Jul 20 '17 at 16:54
  • I understand, but my internet connection is not so good that I can upload the zipped file. It's 142.9 mb( should I be surprised ). but I will try – Saurab Jul 20 '17 at 17:02
  • If there are any .RSA or .SF files in the jar artifact, it will fail to start. – CrazyCoder Jul 20 '17 at 17:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/149740/discussion-between-saurab-and-crazycoder). – Saurab Jul 20 '17 at 17:04

0 Answers0