Maven 依赖问题?

Maven dependencies issue?

我在 IntelliJ 上创建了一个 Maven 项目,它 运行 是正确的。现在,我想 运行 我的项目 Docker 而没有 IntelliJ。

为此,我使用了这个命令:docker run -it --rm --name my-maven-project -v /var/www/html/Recommandation/:/usr/src/mymaven -p 88:88 -w /usr/src/mymaven maven:latest /bin/bash -c "mvn clean install && java -jar target/Recommandation-1.0-SNAPSHOT.jar org.exemple.demo.App"

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  42.037 s
[INFO] Finished at: 2020-07-01T11:33:43Z
[INFO] ------------------------------------------------------------------------
Error: Unable to initialize main class org.exemple.demo.App
Caused by: java.lang.NoClassDefFoundError: io/vertx/core/Verticle

但是存在依赖解析问题。有什么想法吗?

这是我的 pom.xml :

<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>org.exemple.demo</groupId>
    <artifactId>Recommandation</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>org.exemple.demo.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <packaging>jar</packaging>

    <name>Recommandation</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>7</maven.compiler.source>
        <maven.compiler.target>7</maven.compiler.target>
    </properties>

    <dependencies>
    ...
    </dependencies>
</project>

据我所知,您没有将依赖项包含到您的 jar 中。

您需要为此构建一个可执行 jar。

IntelliJ 允许您通过在后台拉取依赖项来 运行 jar,但是如果您想从命令行 运行 一个 jar,它需要包含它的依赖项(或者您需要引用它们来自外部目录)。