简体   繁体   English

在Unix中编译slf4j

[英]Compile slf4j in Unix

I have a Java program that uses slf4j-api-1.7.10.jar and slf4j-simple-1.7.10.jar . 我有一个使用slf4j-api-1.7.10.jarslf4j-simple-1.7.10.jar的Java程序。 I have tried to compile it in my Unix shell like so: 我试图像这样在Unix shell中编译它:

javac -cp "$CLASSPATH:.:slf4j-api-1.7.10.jar:slf4j-simple-1.7.10.jar" Test.java

Running java Test results in this error: 运行java Test导致以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
        at SystemCommandExecutor.<clinit>(SystemCommandExecutor.java:13)
        at Test.main(Test.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
        ... 2 more

I am able to run the program in Windows with the two jar dependencies, so I don't believe I need any extra jars. 我能够在Windows中使用两个jar依赖项来运行该程序,因此我认为我不需要任何额外的jar。 Perhaps I am issuing the wrong command to compile in Unix as I am fairly unfamiliar with the syntax. 也许是因为我不太熟悉语法,所以发出了在Unix中编译的错误命令。

Why you don't create a pom.xml for compile it with a maven dependency? 为什么不创建带有maven依赖关系的pom.xml进行编译?

In that case you should include the package for the main class: 在这种情况下,您应该包括主类的软件包:

javac -classpath external.jar com/yourpackage/yourMainClass.java javac -classpath external.jar com / yourpackage / yourMainClass.java

Also check your syntax for the slf4j inclusion. 还要检查slf4j包含的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM