java.lang.NoClassDefFoundError:org / w3c / tidy / Tidy,Maven项目 [英] java.lang.NoClassDefFoundError: org/w3c/tidy/Tidy , Maven project

查看:562
本文介绍了java.lang.NoClassDefFoundError:org / w3c / tidy / Tidy,Maven项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从命令提示符运行Maven 2中构建的java应用程序

I am trying to run java application built in Maven 2 from command prompt

在命令提示符下我执行了mvn package并获取了目标文件夹中的jar应用程序

On command prompt I did "mvn package" and got the jar in target folder of the application

然后我做了: -

java -cp target / TempestApp.jar foo.App

java -cp target/TempestApp.jar foo.App

我得到例外: -

Exception in thread "main" java.lang.NoclassDefFoundError: org/w3c/tidy/Tidy
      at foo.htmltoxml.HtmlToXMLConvertor(htmltoxml.java:29)
      at foo.app.main(App.java:35)

该申请包含一个JTidy。在POM.xml中提到了谁的依赖关系

The application comprises of a JTidy. Who's dependency is mention in the POM.xml

应用程序在Eclipse中运行良好,但不能从命令提示符运行。

Application runs fine in Eclipse but not from command prompt.

我甚至尝试将JTidy jar放在classpath变量中

I even tried putting the JTidy jar in classpath variable

推荐答案

你可以让maven用类路径中的所有jar启动你的应用程序。使用 exec-maven-plugin 非常容易。

You can let maven start your application with all the jars in the classpath. It is quite easy with the exec-maven-plugin.

将此添加到中pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>com.company.package.YourApplicationMain</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

然后当你想在同一个命令中构建和执行时:

Then when you want to build and execute in the same command:

mvn package exec:java

如果您只想运行该应用程序:

And if you just want to run the application:

mvn exec:java

这篇关于java.lang.NoClassDefFoundError:org / w3c / tidy / Tidy,Maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆