我正在使用Cloudera Manager API获取集群。
我正在使用Maven shade-plugin。
这里有一个与空指针异常相关的另一个问题,但它不能解决我的问题。看起来像是依赖项的问题,因为如果我在IDE中运行应用程序,则可以正常工作。
当我运行自包含的jar文件时,它会失败。我可能缺少什么依赖关系?
以下是源代码:
String host = HOST_PREFIX + args[0];
String command = args[1];
RootResourceV10 apiRoot = new ClouderaManagerClientBuilder()
.withHost(host).withPort(7180)
.withUsernamePassword(ADMIN, ADMIN).build().getRootV10();
if (apiRoot == null) {
System.exit(0);
}
ClustersResourceV10 clusterResource = apiRoot.getClustersResource();
try {
if (command.equals(START)) {
System.out.println("starting..");
ApiCommand cmd = apiRoot.getClustersResource().startCommand(
"cluster"
);
while (cmd.isActive()) {
cmd = apiRoot.getCommandsResource()
.readCommand(cmd.getId());
}
} else {
System.out.println("stopping..");
ApiCommand cmdstop = apiRoot.getClustersResource().stopCommand(
"cluster"
);
while (cmdstop.isActive()) {
cmdstop = apiRoot.getCommandsResource().readCommand(
cmdstop.getId());
}
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
以下是错误信息:
{java.lang.NullPointerException
at org.apache.cxf.jaxrs.client.AbstractClient.setupOutInterceptorChain(AbstractClient.java:850)
at org.apache.cxf.jaxrs.client.AbstractClient.createMessage(AbstractClient.java:900)
at org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:522)
at org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:206)
at com.sun.proxy.$Proxy23.startCommand(Unknown Source)
at com.worksap.company.cloudera.cluster.manage.ClusterManager.main(ClusterManager.java:48)
pom.xml如下所示
<?xml version="1.0" encoding="UTF-8"?>
<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>jp.co.ltd</groupId>
<artifactId>cluster-manager</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>cdh.repo</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos</url>
<name>Cloudera Repository</name>
</repository>
</repositories>
<properties>
<cxf.version>2.7.5</cxf.version>
<guava.version>14.0</guava.version>
<jackson2.version>2.1.0</jackson2.version>
<joda.version>2.1</joda.version>
<junit.version>4.11</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<test.redirectToFile>true</test.redirectToFile>
<privateClassPath>com.cloudera.api.shaded</privateClassPath>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.cloudera.api</groupId>
<artifactId>cloudera-manager-api</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.worksap.company.sample.spark.batch.SparkSample</mainClass>
</transformer>
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<!-- Additional configuration. -->
</configuration>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<extdirs>lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
START
上,因为命令不能为空。如果 args[1] 不存在,Uipiki 应该首先会收到 IndexOutOfBoundException。 - Danielson