【问题标题】:Maven run batch from command line, java.lang.NoClassDefFoundErrorMaven 从命令行运行批处理,java.lang.NoClassDefFoundError
【发布时间】:2013-05-24 23:58:00
【问题描述】:

我在使用 maven 和通过命令行执行 java 类调用时遇到问题。

我的应用程序使用 spring、hibernate 和 maven。

我的 pom.xml 是这样的:

<profile>
<id>import</id>
<build>
 <plugins>
  <plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <executions>
    <execution>
     <goals>
      <goal>java</goal>
     </goals>
     <phase>test</phase>
      <configuration>
        <mainClass>com.mycompany.App</mainClass>
      </configuration>
     </execution>
    </executions>
  </plugin>
 </plugins>
</build>
</profile>

我尝试从 eclipse 运行并且我的应用程序可以运行,而在命令行上是这样的: mvn 测试 -Pimport 我有一些错误,例如:

"nested exception is java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory"

例如:依赖是这样定义的:

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
<scope>runtime</scope>
</dependency>

有什么建议吗?

谢谢

【问题讨论】:

    标签: java maven command-line


    【解决方案1】:

    我认为您可能遇到与this 相同的问题。您的类路径上也应该有一个实现 jar。例如

            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.5.8</version>
            </dependency>
    

    您的 pom.xml 中是否还有其他提到 slf4j 的内容?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      相关资源
      最近更新 更多