java exec执行tar_用java调用rpmbuild 报错,同一条命令直接复制到终端却能运行

用java调用rpmbuild 报错,同一条命令直接复制到终端却能运行。

命令如下:

rpmbuild --define "_topdir /var/lib/jenkins/workspace/compositor-build-CI/target/rpmbuild/compositor" --define "service_desc compositor" --define "service_name compositor" --define "service_release CI.last" -ba SPECS/rpmbuild.spec --clean --target i686-redhat-linux

java调用代码如下:

String rpmBuildScript = String.format("rpmbuild --define \"_topdir %s\" --define \"service_desc %s\" --define \"service_name %s\" --define \"service_release %s\" -ba SPECS/rpmbuild.spec --clean --target i686-redhat-linux", new File(privateRpmBuild).getAbsolutePath(), serviceName, serviceName, version);

getLog().info("RPM build command: " + rpmBuildScript);

Process exec = Runtime.getRuntime().exec(rpmBuildScript, null, new File(privateRpmBuild));

exec.waitFor();

BufferedReader in = new BufferedReader(new InputStreamReader(exec.getErrorStream()));

String line;

while ((line = in.readLine()) != null) {

getLog().info(line);

}

错误输出:

[INFO] RPM build command: rpmbuild --define "_topdir /var/lib/jenkins/workspace/compositor-build-CI/target/rpmbuild/compositor" --define "service_desc compositor" --define "service_name compositor" --define "service_release CI.last" -ba SPECS/rpmbuild.spec --clean --target i686-redhat-linux

[INFO] error: Macro % has illegal name (%define)

[INFO] error: Macro % has illegal name (%define)

[INFO] error: Macro % has illegal name (%define)

[INFO] error: Macro % has illegal name (%define)

[INFO] error: Macro % has illegal name (%define)

[INFO] error: Macro % has illegal name (%define)

[INFO] error: Macro % has illegal name (%define)

[INFO] error: Macro % has illegal name (%define)

[INFO] error: Macro % has illegal name (%define)

[INFO] error: failed to stat /var/lib/jenkins/workspace/compositor-build-CI/target/rpmbuild/compositor": No such file or directory

其中的"error: failed to stat /var/lib/jenkins/workspace/compositor-build-CI/target/rpmbuild/compositor": No such file or directory",这条报错语句有点诡异,我直接用Jenkins用户进去能找到这个目录,并且复制rpmbuild命令并执行能生成正确的rpm文件。

附上rpmbuild.spec文件

%define _builddir %{_topdir}/BUILD

%define _rpmdir %{_topdir}/RPMS

%define _sourcedir %{_topdir}/SOURCES

%define _specdir %{_topdir}/SPECS

%define _srcrpmdir %{_topdir}/SRPMS

%define _buildrootdir %{_topdir}/BUILDROOT

Summary: %{service_desc}

Name: %{service_name}

Version: 1.0

Release: %{service_release}

License: Restricted

Group: Applications/System

Packager: Alain

BuildRoot: %{_buildrootdir}/%{name}-%{version}_%{release}

BuildArchitectures: noarch

%description

This is a sample SPEC file for the RPM project

demonstrating how to build, package, install(deploy)

%prep

# extract the tar file containing all the sources, to the build directory.

echo service_desc = %{service_desc}

echo service_name = %{service_name}

echo service_release = %{service_release}

echo _builddir = %{_builddir}

echo _rpmdir = %{_rpmdir}

echo _sourcedir = %{_sourcedir}

echo _specdir = %{_specdir}

echo _srcrpmdir = %{_srcrpmdir}

echo _buildrootdir = %{_buildrootdir}

%build

echo "Building the project..."

%install

# This is the hierarchy which is going to be inside the package (RPM/Deb) eventually.

echo "Install phase..."

echo %{_topdir}

echo %{buildroot}

mkdir -p %{buildroot}/services/apps

mv %{_builddir}/tar_expand_temp_dir/%{name} %{buildroot}/services/apps

%post

#This runs post the install - maybe you want to execute the application already then

echo "Post install.."

echo "add service.."

cp /services/apps/%{name}/bin/%{name} /etc/init.d

chkconfig --add %{name}

echo "add service succeed"

%postun

#this runs after the uninstall

echo "Post Uninstall..."

echo "remove service"

chkconfig --del %{name}

rm /etc/init.d/%{name}

%files

# tells which files to contain in the package and with what access rights

# the triplet contains of (, , ). Make the necessary changes.

%defattr(-,track,track)

/*

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值