Gaël GRZELAK
Gaël GRZELAK

Reputation: 5

Maven dependencies issue?

I created a Maven project on IntelliJ and it runs correctly. Now, I would like to run my project with Docker and without IntelliJ.

For this, I use this command : 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

But there is a dependency resolution issue. Any idea ?

Here's my 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>

Upvotes: 0

Views: 44

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35805

As I see you did not include the dependencies into your jar.

You need to build an executable jar for that.

IntelliJ allows you to run jars by pulling the dependencies in the background, but if you want to run a jar from command line it needs to include its dependencies (or you need to reference them from an external directory).

Upvotes: 1

Related Questions