繁体   English   中英

使用Maven Eclipse AsciidoctorJ时出现java.lang.NoClassDefFoundError

[英]java.lang.NoClassDefFoundError while using maven eclipse AsciidoctorJ

我正在尝试使用asciidoctor使用asciidocj(convertFile)内置的方法来生成html文件。我正在获取java.lang.NoClassDefFoundError:org / asciidoctor / OptionsBuilder

我正在做月食; Maven和我在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,打包一切工作正常,当我执行程序时出现此错误。 我读到它是关于类路径等的...但是我不知道该怎么做

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


谢谢。

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

我看到您已经有了maven-assembly-plugin 使用mvn clean compile assembly:single然后使用java -jar target/PriseDeNotes-0.0.1-SNAPSHOT-jar-with-dependencies.jar

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

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

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

暂无
暂无

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

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