java.lang.NoClassDefFoundError: org/w3c/tidy/Tidy , Maven project

送分小仙女□ 提交于 2019-12-13 18:27:07

问题


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

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

Then I did:-

java -cp target/TempestApp.jar foo.App

And I get exception:-

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)

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

Application runs fine in Eclipse but not from command prompt.

I even tried putting the JTidy jar in classpath variable


回答1:


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

Add this into your 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



回答2:


There are two options:

java -cp /path/to/jitidy.jar;target/TempestApp.jar TempestMainClass

or

java -cp /path/to/jitidy.jar -jar target/TempestApp.jar

if the MainClass is set in Manifest.mf

Manifest.mf

... Main-Class: package.to.your.MainClass <- NEWLINE!!!



来源:https://stackoverflow.com/questions/12101240/java-lang-noclassdeffounderror-org-w3c-tidy-tidy-maven-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!