所以我有一个基本的Java程序,我试图使用Ant的rpm任务打包为RPM。我是通过Cygwin运行的。我的问题是当我运行ant build脚本时,它似乎试图使用rpm命令而不是所需的rpmbuild命令。根据我的阅读,ant rpm任务应该使用rpmbuild,除非找不到,在这种情况下它使用rpm。我知道两者都安装正确,因为我可以使用命令行手动创建RPM。我不确定在构建脚本或spec文件中是否需要更改以使其正常工作,因为我是这类新手。或者,如果这是一个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" />
这是我的spec文件,非常简单:
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 build的输出(只有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
答案 0 :(得分:0)
如果您想了解ant run中发生的事情,您应该了解您感兴趣的任务的来源。不确定您拥有的ant版本,但最新的来源可以在这里看到:{{3 }}
您感兴趣的方法似乎是:
/**
* 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用户),但是让我提议,我会尝试一下。
-verbose
选项运行ant(如此处所示:http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java?view=markup)并查看它是否告诉您有用的内容我不知道cygwin中可执行文件的外观,但问题是它们是否有.exe
扩展名。另一个重要的问题是如果Os.isFamily("dos")
在cygwin中被评估为真。
玩得开心:)