Alexander Shavelev
Alexander Shavelev

Reputation: 324

maven doesn't pack lib to jar

I have the next situation

git clone https://github.com/Ozey/telegramBot
cd telegramBot
./start.sh

and get the next error
[INFO] ------------------------------------------------------------------------
Test!
Exception in thread "main" java.lang.NoClassDefFoundError: org/telegram/telegrambots/bots/TelegramLongPollingBot

can't understand why this lib isn't in jar file

Upvotes: 1

Views: 1323

Answers (2)

silb78
silb78

Reputation: 139

try this one:

<?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>MyFirstProject</groupId>
<artifactId>MyFirstProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>MyFirstProject</name>

<properties>
    <jdk.version>1.8</jdk.version>
</properties>

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>



<dependencies>
    <dependency>
        <groupId>com.github.rubenlagus</groupId>
        <artifactId>TelegramBots</artifactId>
        <version>v2.3.3.3</version>
    </dependency>

    <dependency>
        <groupId>org.twitter4j</groupId>
        <artifactId>twitter4j-core</artifactId>
        <version>4.0.4</version>
    </dependency>
</dependencies>


<build>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                      <includeScope>runtime</includeScope>
                      <outputDirectory>${project.build.directory}/lib/</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <configuration>
              <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>api.Test</mainClass>
                    <classpathPrefix>lib/</classpathPrefix>
                </manifest>
              </archive>
            </configuration>
          </plugin>
    </plugins>
</build>

Upvotes: 2

Sonal
Sonal

Reputation: 272

Add this plugin to your project pom.xml

<plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>WebContent/WEB-INF/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

This will copy all libraries into lib folder when you will run mvn clean install command. when you will generate final jar or war, you will get all the libraries

Upvotes: 0

Related Questions