当前位置: 首页 > 知识库问答 >
问题:

java.lang.NoClassDefFoundError Jackrabbit FirstHop example

文心思
2023-03-14

我是Maven和杰克兔的新手,我从Apache网站上给出的FirstHops示例开始,但是当尝试运行时,我得到以下错误。不知道要检查什么。

S:\mvnapp\FirstHop2>java -cp target\FirstHop2-1.0-SNAPSHOT.jar org.shobhan.jr.Fi
rstHopSB
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jcr/Credentials

Caused by: java.lang.ClassNotFoundException: javax.jcr.Credentials
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: org.shobhan.jr.FirstHopSB.  Program will exit.

下面是Pom.xml文件,我已经添加了apache站点上提供的依赖项。

<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>org.shobhan.jr</groupId>
  <artifactId>FirstHop2</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>FirstHop2</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

    <dependencies> 
    <!-- The JCR API --> 
        <dependency> 
            <groupId>javax.jcr</groupId> 
            <artifactId>jcr</artifactId> 
            <version>2.0</version> 
        </dependency> 
        <!-- Jackrabbit content repository --> 
        <dependency> 
            <groupId>org.apache.jackrabbit</groupId> 
            <artifactId>jackrabbit-core</artifactId> 
            <version>2.9.0</version> 
        </dependency> 
        <!-- Use Log4J for logging --> 
        <dependency> 
            <groupId>org.slf4j</groupId> 
            <artifactId>slf4j-log4j12</artifactId> 
            <version>1.7.5</version> 
        </dependency> 
    </dependencies> 
</project>

我的环境。具有以下值。

class path = C:\ Program Files \ Java \ JDK 1 . 6 . 0 _ 17 \ bin;s:\ JR \ jack rabbit-standalone-2 . 8 . 0 . jar JAVA _ HOME = C:\ Program Files \ JAVA \ JDK 1 . 6 . 0 _ 17

M2_HOME=S:\maven\apache-maven-3.2.5路径=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;S: \maven\apache-maven-3.2.5\bin;C: \Program Files\Java\jdk1.6.0_17\bin

共有1个答案

卫梓
2023-03-14

您的问题是您没有在目标jar中包含您的依赖项:将它添加到您的pom.xml:

<build>
  <plugins>
    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>com.mypackage.main.Main</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>

然后运行目标:

clean package assembly:single 
 类似资料:

相关问答

相关文章

相关阅读