我正在尝试使用在Apache网站上提供的Jackrabbit 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>
我的环境低于值。
CLASSPATH = C:\ Program Files \ Java \ jdk1.6.0_17 \ bin; S:\ JR \ jackrabbit-standalone-2.8.0.jar JAVA_HOME = C:\ Program Files \ Java \ jdk1.6.0_17
M2_HOME = S:\ maven \ apache-maven-3.2.5 PATH =%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
答案 0 :(得分:0)
此错误,“NoClassDefFound”在编译时存在库时发生,但不在运行时类路径中。它几乎总是意味着运行时类路径缺少JAR。如果要对其进行硬编码,则需要在类路径中包含jcr jar。
更好的方法是使用maven exec:java插件。更新:Here is a gist with a working pom.xml
尝试在“depdendencies”之后将其添加到pom.xml中。
<build><plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<classpathScope>compile</classpathScope>
<mainClass>com.whatever.MyMainClassy</mainClass>
</configuration>
</plugin>
</plugins></build>
然后您可以使用
运行mvn exec:java
它将使用与编译时相同的类路径。
在本地测试,您的输出应如下所示:
mvn exec:java
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building FirstHop2 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ FirstHop2 >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ FirstHop2 <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ FirstHop2 ---
Logged in as anonymous to a Jackrabbit repository.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.420s
[INFO] Finished at: Mon Jan 12 15:27:03 EST 2015
[INFO] Final Memory: 17M/231M
[INFO] ------------------------------------------------------------------------
答案 1 :(得分:0)