1

所以我有一个基本的 Java 程序,我正在尝试使用 Ant 的rpm任务将其打包为 RPM。我正在通过 Cygwin 运行它。我的问题是当我运行 ant 构建脚本时,它似乎试图使用 rpm 命令而不是所需的 rpmbuild 命令。根据我的阅读,ant rpm 任务应该使用 rpmbuild 除非找不到,在这种情况下它会使用 rpm。事实上,我知道两者都已正确安装,因为我可以使用命令行手动创建 RPM 就好了。我不确定是否需要在构建脚本或规范文件中更改某些内容才能使其正常工作,因为我对这种事情不熟悉。或者,如果这是 Cygwin 依赖问题?

在 Cygwin 中安装 rpm 和 rpmbuild 的证明:

$ 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" />

这是我的规范文件,非常简单:

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

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

%files

最后,这是 ant 构建的输出(仅 rpm 部分):

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
4

1 回答 1

0

如果您想查看 ant run 中发生了什么,您应该了解您感兴趣的任务的来源。不确定您拥有的 ant 版本,但可以在此处查看最新的来源: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. 如果没有,请尝试下载 ant 源代码(您使用的版本),将它们导入您最喜欢的 java ide 并进行远程调试以查看发生了什么。我会在第 333 行附近放置断点,以查看是否找到了 rpmbuild。如果您不确定如何为 ant 设置远程调试,请参阅: http: //www.vitorrodrigues.com/blog/2009/07/10/debugging-ant-tasks-in-eclipse/

我不知道可执行文件在 cygwin 中的外观,但问题是它们是否有.exe扩展名。另一个重要的问题是Os.isFamily("dos")在 cygwin 中是否会被评估为真。

玩得开心 :)

于 2013-07-16T06:29:09.047 回答