有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Maven依赖性问题?

我在IntelliJ上创建了一个Maven项目,它运行正常。现在,我想在没有IntelliJ的情况下使用Docker运行我的项目

为此,我使用以下命令: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>

共 (1) 个答案

  1. # 1 楼答案

    正如我看到的,您没有将依赖项包括到您的jar中

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

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