2014-09-25 36 views
0

我正在尝试使用apache twill构建YARN应用程序。从twill presentation的幻灯片中,他们正在讨论使用maven-bundle-plugin打包hello world样本。如何打包并运行斜纹示例应用程序

因此,要打包示例hello world,我首先尝试打包与mvn assembly:assembly -DdescriptorId=jar-with-dependencies的罐子。 然后通过添加以下到pom.xml(和做mvn clean install):

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>maven-bundle-plugin</artifactId> 
     <version>2.5.3</version> 
     <extensions>true</extensions> 
     <configuration> 
     <instructions> 
      <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName> 
      <Bundle-Name>${pom.artifactId}</Bundle-Name> 
      <Bundle-Version>1.0.0</Bundle-Version> 
      <Private-Package>org.wso2.mbp.helloworld</Private-Package> 
      <Bundle-Activator>org.wso2.mbp.helloworld.Activator</Bundle-Activator> 
      <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> 
      <Embed-Transitive>true</Embed-Transitive> 
      <Import-Package> 
      org.apache.twill.*, 
      org.osgi.framework, 
      *;resolution:=optional 
      </Import-Package> 
     </instructions> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 

如何斜纹应用程序打包在一起?然后如何在hadoop上运行它们?

回答

2

对于包装,您可以使用maven-bundle-plugin。我平时都像这样在pom.xml中:

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>maven-bundle-plugin</artifactId> 
     <version>2.3.7</version> 
     <extensions>true</extensions> 
     <configuration> 
     <instructions> 
      <Embed-Dependency>*;inline=false;groupId=!org.apache.hadoop</Embed-Dependency> 
      <Embed-Transitive>true</Embed-Transitive> 
      <Embed-Directory>lib</Embed-Directory> 
     </instructions> 
     </configuration> 
     <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
      <goal>bundle</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

然后运行MAVEN_OPTS="-Xmx512m" mvn clean package。这应该在目标目录下创建一个.jar文件。如果用“罐子-tf”看jar文件的内容,就应该是这样的:

my/package/HelloWorld.class 
my/package/HelloWorld$HelloWorldRunnable.class 
lib/twill-api-0.3.0-incubating.jar 
lib/twill-core-0.3.0-incubating.jar 
lib/.. 

要启动应用程序,请确保您可以访问Hadoop集群的主机上您计划启动应用程序。然后你就可以scp和其unjar在某些目录中的文件,然后shell命令这样的扩展JAR目录:

$> export HADOOP_CP=`hadoop classpath` 
$> java -cp .:lib/*:$HADOOP_CP my.package.HelloWorld 

的将HelloWorld内的main()方法应该能够与动物园管理员和纱线和互动启动集群中的应用程序。

+0

with'jar -tf twill-sample.jar'我没有看到'lib/*'文件夹! – bachr 2014-11-05 10:28:12

+0

如果包装类型是“jar”,则捆绑插件实际上需要执行目标来构建捆绑包jar。我更新了我的答案以反映这一点。还包括捆绑插件中的hadoop排除,以便它不会包含hadoop罐子。 – 2014-11-06 00:09:29

+0

它的工作原理,但我不得不手动下载[hadoop-auth-2.5.0.jar](http://mvnrepository.com/artifact/org.apache.hadoop/hadoop-auth/2.5.0)(for'org。 apache.hadoop.util.PlatformName'),因为它在我的hadoop安装中丢失了。 – bachr 2014-11-06 10:19:20

相关问题