简体   繁体   中英

WordCount example runs in Eclipse, but not in terminal

I tried running first of the WordCount examples and it works in Eclipse (I have Windows 7 OS), but not in shell, using the command:

mvn compile exec:java -Dexec.mainClass=com.google.cloud.dataflow.examples.MinimalWordCount

I have installed Maven and configured JAVA_HOME and Path variables and so on, however, I'm not sure what I must have missed. This is the output:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Tutorial 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Tutorial ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Java\eclipse-jee-luna-SR2-win32-x8
6_64\eclipse\workspace\Tutorial\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ Tutorial --
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ Tutorial ---
[WARNING]
java.lang.ClassNotFoundException: com.google.cloud.dataflow.examples.MinimalWord
Count
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
    at java.lang.Thread.run(Thread.java:744)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.011 s
[INFO] Finished at: 2015-11-03T01:11:57+01:00
[INFO] Final Memory: 17M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java 
(default-cli) on project Tutorial: An exception occured while executing the Java 
class. com.google.cloud.dataflow.examples.MinimalWordCount -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please
read the following articles:
[ERROR] [Help 1]    http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception-

I am in the dark about how to proceed and would very much appreciate ideas of where to look next and other things to try.

Thanks!

You may have run into an issue with the documentation.

The command line you are using should work if you have cloned GoogleCloudPlatform/DataflowJavaSDK-examples . The mention of the particular repo to clone is way back in " getting started ", not at all obvious if you head straight to WordCount Example Pipeline .

But if you generated the project from the Cloud Dataflow Plugin for Eclipse (or via a Maven archetype ) then the examples are placed into your Java package. So instead of com.google.cloud.dataflow.examples.MinimalWordCount you will use the name my.java.project.MinimalWordCount , where my.java.project is whatever package name you chose when you created the project.

Or if you have cloned the SDK itself from GoogleCloudPlatform/DataflowJavaSDK then you will need to add -pl examples to your command line. This is because the SDK's repository is factored into maven modules; this flag instructs maven to run in the context of the examples module.

如果您有一个多模块Maven项目(DataflowJavaSDK,而不是DataflowJavaSDK-examples),则可以在顶层目录中执行mvn compile ,然后在cd插入examples ,然后在其中mvn exec:java -Dexec.mainClass=...命令。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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