【问题标题】:java.lang.NoClassDefFoundError while using maven eclipse AsciidoctorJjava.lang.NoClassDefFoundError 使用 maven eclipse AsciidoctorJ
【发布时间】:2019-04-30 23:36:16
【问题描述】:

我正在尝试使用 Asciidoctor 使用 asciidocj (convertFile) 中内置的方法生成 html 文件 我收到 java.lang.NoClassDefFoundError:org/asciidoctor/OptionsBuilder

我正在研究 eclipse ;行家和 我在 pom.xml 文件中添加了 Asciidoctor 依赖项。

public void view(String document) {
        OptionsBuilder op = OptionsBuilder.options().toFile(false);

        Asciidoctor asciidoctor = create();

        String html = asciidoctor.convertFile(new File(this.path + "/" + document + ".adoc"), op.asMap());
        System.out.println(html);
    }
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>ProgGl</groupId>
   <artifactId>PriseDeNotes</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>
   <name>PriseDeNotes</name>
   <description>Projet de Prog Gl</description>
   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <maven.compiler.source>1.8</maven.compiler.source>
      <maven.compiler.target>1.8</maven.compiler.target>
      <main-class>ProgGl.PriseDeNote.App</main-class>
   </properties>
   <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
               <archive>
                  <manifest>
                     <mainClass>${main-class}</mainClass>
                  </manifest>
               </archive>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>1.5.6</version>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.3</version>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.7</version>
         </plugin>
         <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
               <descriptorRefs>
                  <descriptorRef>jar-with-dependencies</descriptorRef>
               </descriptorRefs>
               <archive>
                  <manifest>
                     <mainClass>${main-class}</mainClass>
                  </manifest>
               </archive>
            </configuration>
            <executions>
               <execution>
                  <id>make-assembly</id>
                  <phase>package</phase>
                  <goals>
                     <goal>single</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.0.1</version>
            <executions>
               <execution>
                  <id>attach-sources</id>
                  <phase>package</phase>
                  <goals>
                     <goal>jar-no-fork</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>3.0.0-M1</version>
            <executions>
               <execution>
                  <id>attach-javadocs</id>
                  <phase>package</phase>
                  <goals>
                     <goal>jar</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-maven-plugin</artifactId>
            <version>3.1.7</version>
            <dependencies>
               <!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
               <dependency>
                  <groupId>com.github.spotbugs</groupId>
                  <artifactId>spotbugs</artifactId>
                  <version>3.1.8</version>
               </dependency>
            </dependencies>
         </plugin>
      </plugins>
   </build>
   <reporting>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.0.0</version>
            <reportSets>
               <reportSet>
                  <reports>
                     <report>checkstyle</report>
                  </reports>
               </reportSet>
            </reportSets>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jxr-plugin</artifactId>
            <version>2.3</version>
         </plugin>
      </plugins>
   </reporting>
   <dependencies>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj</artifactId>
            <version>2.0.0</version>
        </dependency>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.12</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.hamcrest</groupId>
         <artifactId>hamcrest-all</artifactId>
         <version>1.3</version>
         <scope>test</scope>
      </dependency>
   </dependencies>
</project>

mvn install, package 一切正常, 当我执行程序时,我收到了这个错误。 我读到它是关于类路径等的......但我不明白该怎么做

Exception in thread "main" java.lang.NoClassDefFoundError: org/asciidoctor/OptionsBuilder
    at ProgGl.PriseDeNote.Application.view(Application.java:171)
    at ProgGl.PriseDeNote.Commands.ViewCommand.execute(ViewCommand.java:22)
    at ProgGl.PriseDeNote.App.main(App.java:66)
Caused by: java.lang.ClassNotFoundException: org.asciidoctor.OptionsBuilder
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 3 more


谢谢。

【问题讨论】:

  • 你是如何尝试运行程序的?
  • java -jar 目标/PriseDeNotes-0.0.1-SNAPSHOT.jar

标签: java eclipse maven noclassdeffounderror asciidoc


【解决方案1】:

一般来说,maven 程序集插件会生成另一个.jar,称为target/PriseDeNotes-0.0.1-SNAPSHOT-jar-with-dependencies.jar。 您可以尝试java -jar target/PriseDeNotes-0.0.1-SNAPSHOT-jar-with-dependencies.jar 运行应用程序。

【讨论】:

    【解决方案2】:

    我看到你已经有了maven-assembly-plugin。使用mvn clean compile assembly:single 编译,然后使用java -jar target/PriseDeNotes-0.0.1-SNAPSHOT-jar-with-dependencies.jar 运行。

    【讨论】:

      【解决方案3】:

      我认为问题在于,maven 不会将依赖项复制到 jar 中。尝试使用您可以在此处找到的相关插件复制目标中的依赖项:

      https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html

      这样,它应该将所需的依赖项复制到目标文件夹。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-18
        • 1970-01-01
        • 2019-08-05
        • 2021-03-07
        • 1970-01-01
        • 2015-06-16
        • 2020-01-22
        • 2016-08-13
        相关资源
        最近更新 更多