我是Maven和Jackrabbit的新手,我从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>
我的环境低于值。
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:\行家\ Apache的行家-3.2.5 PATH =%SYSTEMROOT%\ SYSTEM32;%SYSTEMROOT%;%SYSTEMROOT%\ System32下\ WBEM;%SYSTEMROOT%\ System32下\ WindowsPowerShell \ V1.0 \; S:\行家\ Apache的行家-3.2.5 \ BIN; C: \ Program Files \ Java \ jdk1.6.0_17 \ bin
答案 0 :(得分:0)
您的问题是您没有在目标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