简体   繁体   English

添加 maven 依赖项时无法找到或加载主类错误

[英]Could not find or load main class error when adding maven dependency

I got a Maven project which is exported into a JAR and works fine.我有一个 Maven 项目,它被导出到一个 JAR 中并且工作正常。 As soon as I add Maven dependency (not using any class etc, just imported)一旦我添加了 Maven 依赖项(不使用任何类等,只是导入)

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

the exported JAR throws the following error:导出的 JAR 会引发以下错误:

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.我必须使用这个 Lib,但是当它只导入而不使用时就已经发生了错误。

pom.xml 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>

The command I use from command line is "java -jar myapp.jar"我从命令行使用的命令是“java -jar myapp.jar”

You need to specify the classpath for your app if you run it as a jar from the command line.如果您从命令行将其作为jar运行,则需要为您的应用程序指定类路径。 See this post .看到这个帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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