slf4j依赖项的Maven运行时错误

时间:2017-07-23 20:54:05

标签: java maven runtime-error slf4j

我的pom.xml依赖项如下所示:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.5</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.5</version>
</dependency>

我也在构建依赖jar,如下所示:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.dstsystems.gig.gploader.Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

maven package创建两个jar,一个具有依赖关系,另一个在目标文件夹中没有依赖关系。这给了我两个可能的用法,但两个都给我运行时错误如下:

用法1:

java -cp target/GPLoader-0.1.4-jar-with-dependencies.jar:prod/compDSPConfig/ com.dstsystems.gig.gploader.Main -p $appProperties

错误:

log4j:WARN No appenders could be found for logger (com.dstsystems.gig.gploader.utils.ApplicationProperties).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

用法2:

java -cp target/GPLoader-0.1.4.jar:prod/compDSPConfig/ com.dstsystems.gig.gploader.Main -p $appProperties

错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.dstsystems.gig.gploader.Main.<clinit>(Main.java:14)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

正如您所知,我不是非常精通java,但需要成功运行此项目才能将此应用程序用于处理文件摄取的Python包装器功能。请帮忙!

1 个答案:

答案 0 :(得分:1)

将以下依赖项用于pom.xml并更新项目并运行它:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.25</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.25</version>
    <scope>test</scope>
</dependency>