在python

时间:2015-09-21 15:33:13

标签: java python

我使用此代码[1]在python中调用java命令,但是我在[2]中得到了错误。我正在使用python(而不是jpython),我希望python能够理解这是一个异常,所以它可以抛出它。有没有办法在python中捕获java异常?

[1]代码调用java命令     command =" hadoop jar examples.jar wordcount / input1 / output1"

process = subprocess.Popen(
    shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = process.communicate()
output = out[stdout]

[2] java异常

java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
    at org.apache.hadoop.mapred.examples.MyWordCount.main(MyWordCount.java:146)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:71)
    at org.apache.hadoop.util.ProgramDriver.run(ProgramDriver.java:144)
    at org.apache.hadoop.mapred.examples.ExampleDriver.main(ExampleDriver.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)

0 个答案:

没有答案