0

I got a Maven project which is exported into a JAR and works fine. As soon as I add Maven dependency (not using any class etc, just imported)

<dependency>
    <groupId>technology.tabula</groupId>
    <artifactId>tabula</artifactId>
    <version>1.0.5</version>
</dependency>

the exported JAR throws the following error:

Error: Could not find or load main class main.MyMain

Any tips how to solve this problem? I have to use this Lib, but the error already occurs when it's only imported, not used.

pom.xml

<?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>my.group</groupId>
    <artifactId>my-art</artifactId>
    <version>1.0</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.dropbox.core</groupId>
            <artifactId>dropbox-core-sdk</artifactId>
            <version>3.1.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.10</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.13.1</version>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>technology.tabula</groupId>-->
            <!--<artifactId>tabula</artifactId>-->
            <!--<version>1.0.5</version>-->
        <!--</dependency>-->
    </dependencies>
</project>
K.Gabor
  • 89
  • 2
  • 11

1 Answers1

0

The command I use from command line is "java -jar myapp.jar"

You need to specify the classpath for your app if you run it as a jar from the command line. See this post.

Arthur Klezovich
  • 2,595
  • 1
  • 13
  • 17
  • Simply with the "java -jar myapp.jar" command or with the specified "java -cp myapp.jar main.MyMain" command my app works. As soon as I import the mentioned dependency both commands give the same error I asked in my question. – K.Gabor Nov 04 '21 at 11:04
  • Does it run from an IDE with/without this dependency ? – Arthur Klezovich Nov 04 '21 at 11:07
  • From IDE there is no problem, works both with and without this dependency – K.Gabor Nov 04 '21 at 11:50
  • > From IDE there is no problem, works both with and without this dependency – This indicates that the problem is with the command you use to run the app from the command line. If you want to run it from the CLI use the same java command your IDE uses to run the app. Here's how to do it if you are using Intellij https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000321520-How-to-view-command-line-string-used-by-Intellij-to-invoke-Java-process- – Arthur Klezovich Nov 04 '21 at 11:53
  • The error probably has to do with the -classpath flag – Arthur Klezovich Nov 04 '21 at 11:54
  • I copied the whole IntelliJ command from the IDE's console. Same. Works without the dependency, doesn't work with it. – K.Gabor Nov 04 '21 at 12:48
  • Is it possible that this error has something to do with signed/not signed JARs? I created a simple HelloWord project with only this dependency, and when I try to execute my JAR I got "A JNI error has occured, please check your installation and try again" error and "Invalid signature file digest for Manifest main attributes" exception. – K.Gabor Nov 04 '21 at 13:03
  • Its so weird ... same command from IDE works, but from the CLI it does not ... maybe you are running this command from the wrong directory ? Try running it from the same directory as IntelliJ does ! – Arthur Klezovich Nov 04 '21 at 13:28
  • I ran every command from the exact same dir. Also when it worked (without the dependency) and also when it didn't. – K.Gabor Nov 04 '21 at 14:03
  • I mean from the same directory as IntelliJ uses to run them. – Arthur Klezovich Nov 04 '21 at 14:04
  • Yes, everything is the same. – K.Gabor Nov 05 '21 at 08:39