2013-07-15 454 views
1

所以我有一個基本的Java程序,我試圖用Ant的rpm任務打包爲RPM。我通過Cygwin運行它。我的問題是當我運行ant build腳本時,它似乎試圖使用rpm命令而不是所需的rpmbuild命令。從我讀過的內容來看,ant rpm任務應該使用rpmbuild,除非找不到,在這種情況下,它將使用rpm。我知道一個事實都安裝正確,因爲我可以使用命令行手動創建RPM就好了。我不確定是否需要在構建腳本或spec文件中更改某些內容才能使其發揮作用,因爲我對這類事情很陌生。或者如果這是Cygwin依賴性問題?在Cygwin上使用Ant創建RPM

證明轉和的rpmbuild的安裝Cygwin中:

$ which rpm 
/usr/bin/rpm 

$ which rpmbuild 
/usr/bin/rpmbuild 

這裏是我的build.xml文件:

<project name="SimpleJavaApp" default="all"> 

<property name="src"  value="${basedir}/src" /> 
<property name="output"  value="${basedir}/output" /> 
<property name="classes" value="${output}/classes" /> 
<property name="jars"  value="${output}/jars" /> 
<property name="build.dir" value="${basedir}/build"/> 

<target name="clean"> 
    <delete dir="${output}" /> 
</target> 

<target name="compile"> 
    <mkdir dir="${classes}" /> 
    <javac srcdir="${src}" destdir="${classes}" /> 
</target> 

<target name="jar"> 
    <mkdir dir="${jars}" /> 
    <jar basedir="${classes}" destfile="${jars}/app.jar"> 
     <manifest> 
       <attribute name="Main-Class" value="Main"/> 
     </manifest> 
    </jar> 
</target> 

<!-- Create directories --> 
<mkdir dir="${build.dir}/BUILD"/> 
<mkdir dir="${build.dir}/SOURCES"/> 
<mkdir dir="${build.dir}/RPMS/noarch"/> 
<mkdir dir="${build.dir}/SPECS"/> 

<!-- copy spec files --> 
<copy todir="${build.dir}/SPECS" preservelastmodified="true" failonerror="true"> 
    <fileset dir="${basedir}" includes="*.spec"/> 
</copy> 

<target name="rpm" description="Compile single binary rpm by spec file"> 
    <rpm 
     specFile="project.spec" 
     topDir="build" 
     cleanBuildDir="false" 
     removeSpec="false" 
     removeSource="false" 
     command = "ba" 
     failOnError="false" 
    /> 
</target> 


<target name="all" depends="clean, compile, jar, rpm" /> 

這裏是我的spec文件,prett Ÿ簡單:

Summary: An RPM Spec example 
Name:  Application-Example 
Version: 1.0 
Release: 1 
Group: Applications/Sample 
URL:  http://www.mycompany.com 
Packager: Name <[email protected]> 
BuildArch: noarch 

%description 
This is a sample SPEC file for the RPM project 
demonstrating how to build, package, install(deploy) 

%files 

最後,這裏是Ant構建的輸出(只轉一部分):

rpm: 
    [rpm] Building the RPM based on the project.spec file 
    [rpm] RPM version 4.1 
    [rpm] Copyright (C) 1998-2002 - Red Hat, Inc. 
    [rpm] This program may be freely redistributed under the terms of the GNU GPL 
    [rpm] 
    [rpm] Usage: rpm [-a|--all] [-f|--file] [-g|--group] [-p|--package] [--specfile] 
    [rpm]   [--whatrequires] [--whatprovides] [-c|--configfiles] [-d|--docfiles] 
    [rpm]   [--dump] [-l|--list] [--queryformat=QUERYFORMAT] [-s|--state] 
    [rpm]   [--nomd5] [--nofiles] [--nodeps] [--noscript] [--addsign] 
    [rpm]   [-K|--checksig] [--import] [--resign] [--nodigest] [--nosignature] 
    [rpm]   [--initdb] [--rebuilddb] [--allfiles] [--allmatches] [--badreloc] 
    [rpm]   [-e|--erase <package>+] [--excludedocs] [--excludepath=<path>] 
    [rpm]   [--force] [-F|--freshen <packagefile>+] [-h|--hash] [--ignorearch] 
    [rpm]   [--ignoreos] [--ignoresize] [-i|--install] [--justdb] [--nodeps] 
    [rpm]   [--nomd5] [--noorder] [--nosuggest] [--noscripts] [--notriggers] 
    [rpm]   [--oldpackage] [--percent] [--prefix=<dir>] [--relocate=<old>=<new>] 
    [rpm]   [--repackage] [--replacefiles] [--replacepkgs] [--test] 
    [rpm]   [-U|--upgrade <packagefile>+] [-D|--define 'MACRO EXPR'] 
    [rpm]   [-E|--eval 'EXPR'] [--macros=<FILE:...>] [--nodigest] [--nosignature] 
    [rpm]   [--rcfile=<FILE:...>] [-r|--root ROOT] [--querytags] [--showrc] 
    [rpm]   [--quiet] [-v|--verbose] [--version] [-?|--help] [--usage] 
    [rpm]   [--scripts] [--setperms] [--setugids] [--conflicts] [--obsoletes] 
    [rpm]   [--provides] [--requires] [--info] [--changelog] [--triggers] 
    [rpm]   [--last] [--filesbypkg] [--redhatprovides] [--redhatrequires] 
    [rpm]   [--buildpolicy=<policy>] [--with=<option>] [--without=<option>] 

all: 

BUILD SUCCESSFUL 
Total time: 1 second 

回答

0

,如果你想看到什麼是螞蟻運行情況發生,你應該瞭解你感興趣的任務的來源不知道你有什麼螞蟻版本,但最近的源代碼可以在這裏看到:http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java?view=markup

的興趣的方法似乎是:

/** 
* Checks whether <code>rpmbuild</code> is on the PATH and returns 
* the absolute path to it - falls back to <code>rpm</code> 
* otherwise. 
* 
* @return the command used to build RPM's 
* 
* @since 1.6 
*/ 
protected String guessRpmBuildCommand() { 
    Map/*<String, String>*/ env = Execute.getEnvironmentVariables(); 
    String path = (String) env.get(PATH1); 
    if (path == null) { 
     path = (String) env.get(PATH2); 
     if (path == null) { 
      path = (String) env.get(PATH3); 
     } 
    } 

    if (path != null) { 
     Path p = new Path(getProject(), path); 
     String[] pElements = p.list(); 
     for (int i = 0; i < pElements.length; i++) { 
      File f = new File(pElements[i], 
           "rpmbuild" 
           + (Os.isFamily("dos") ? ".exe" : "")); 
      if (f.canRead()) { 
       return f.getAbsolutePath(); 
      } 
     } 
    } 

    return "rpm"; 
} 

的下文稱常數是:

private static final String PATH1 = "PATH"; 
private static final String PATH2 = "Path"; 
private static final String PATH3 = "path"; 

就像你提到的,它基本上只是試圖找到自己的路徑上rpmbuild。如果找不到它,則用於rpm

事情是,我沒有安裝cygwin(因爲我是一個Linux用戶),但讓我建議,我想試試。

  1. 嘗試與-verbose選項運行ant(如下建議:http://ant.apache.org/problems.html),看看它會告訴你一些有用的東西
  2. 如果沒有,請嘗試下載螞蟻源(您使用的版本),將其導入你最喜歡的Java IDE,並做遠程調試,看看發生了什麼。我會把斷點放在333行左右,看看是否找到了rpmbuild。如果你不知道如何爲螞蟻設置遠程調試,請參見:http://www.vitorrodrigues.com/blog/2009/07/10/debugging-ant-tasks-in-eclipse/

我不知道可執行文件怎麼看在Cygwin中,但問題是,如果他們有.exe擴展。另一個重要問題是如果Os.isFamily("dos")將在cygwin中被評估爲true。

玩得開心:)