所以我有一个基本的 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