我是JAVA的新手,想要运行一份在线上找到的样例程序。
我从github下载了一个包 https://github.com/yiming187/curator-example
我使用命令mvn package
对其进行编译。
结果显示BUILD SUCCESS。
[vagrant@bb720864d128 curator-example]$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building curator-example 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ curator-example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /vagrant/curator-example/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ curator-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ curator-example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /vagrant/curator-example/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ curator-example ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ curator-example --
-
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ curator-example ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.767s
[INFO] Finished at: Tue Oct 27 22:27:29 UTC 2015
[INFO] Final Memory: 8M/237M
[INFO] ------------------------------------------------------------------------
我随后找到了目标文件curator-example-0.0.1-SNAPSHOT.jar,并尝试运行其中的一个示例,但它无法正常工作。
命令如下:
java -cp curator-example-0.0.1-SNAPSHOT.jar com/ctrip/zk/curator/example/DistributedIdQueueExample
输出结果为:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
CuratorFramework cannot be resolved to a type
DistributedIdQueue cannot be resolved to a type
CuratorFrameworkFactory cannot be resolved
ExponentialBackoffRetry cannot be resolved to a type
CuratorListener cannot be resolved to a type
CuratorFramework cannot be resolved to a type
CuratorEvent cannot be resolved to a type
QueueConsumer cannot be resolved to a type
The method createQueueConsumer() from the type DistributedIdQueueExample refers to the missing type QueueConsumer
QueueBuilder cannot be resolved to a type
QueueBuilder cannot be resolved
The method createQueueSerializer() from the type DistributedIdQueueExample refers to the missing type QueueSerializer
CloseableUtils cannot be resolved
CloseableUtils cannot be resolved
at com.ctrip.zk.curator.example.DistributedIdQueueExample.main(DistributedIdQueueExample.java:20)
pom.xml
<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>com.ctrip.zk</groupId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<artifactId>curator-example</artifactId>
<name>curator-example</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.7.1</version>
</dependency>
</dependencies>
</project>
jar
的POM将生成适合包含在其他项目中的jar文件。 - watery