0

I have a problem with making executable jar from my project. I've made a test project with the name

test_project

there is 1 package

testpack

and a public class with my main()

testclass

     package testpack;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

 public class testclass{

    public static void main(String[] args) throws IOException {...}

I have tried to plugins maven-jar-plugin and maven-assembly-plugin just to see what the difference; in both cases i have the same problem with

   <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>testpack.testclass</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
    </plugin>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>testpack.testclass</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

Error: Could not find or load main class testpack.testclass

yes I have read this similar question and it didn't help me

I've checked my env variables and all the step 1 points; I think i just don't understand how to point on my main() in maven setup

I don't understand were can I find this information about my project

<archive>
    <manifest>
      <mainClass>com.domain.project.MainClass</mainClass>
    </manifest>
  </archive>

what's the right way to point on the main class?

Vladimir Zaguzin
  • 191
  • 5
  • 22

1 Answers1

1

Please check below the maven jar plugin usage. I have written a simple Hello World Program just to demonstrate.

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>
                                com.ddlab.rnd.App
                            </mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

If you want to check the complete small source code, check this github link. https://github.com/debjava/runnableJar

I did not add any classpath dependencies, if you want, you can add other libraries like this.

<addClasspath>true</addClasspath>
<classpathPrefix>you lib dir containing all jar file/</classpathPrefix>
Sambit
  • 7,625
  • 7
  • 34
  • 65