Policies/Java/Native

From Mandriva Community Wiki

Jump to: navigation, search
Mandriva Linux Native Java Packaging Policy

This page discusses packaging Java applications for Mandriva Linux along with GCJ AOT-compiled libraries.

Contents


[edit] Rules for ant-based builds

  • Clean the upstream source tarball of any jar or class files and repackage it (rationale: license issues (non-freeness), diskspace, etc.).
  • Always use the Epoch tag and epochs in any versioned provides or requires, and always put the epoch in the %changelog (due to JPackage versioning) (rationale: having o epoch leads to non-deterministic behavior).
  • Always use:
Group: Development/Java

(rationale: users can grab/search Java packages by group).

  • Typically, you will always have the following:
Requires: java
Requires: jpackage-utils
BuildRequires: ant
BuildRequires: java-devel
BuildRequires: jpackage-utils
  • For the ant style task (or any ant task, really), you will need to set OPT_JAR_LIST (not CLASSPATH) and include the following:
BuildRequires: ant-nodeps
BuildRequires: ant-trax
BuildRequires: docbook-style-xsl
BuildRequires: jaxp_transform_impl
BuildRequires: xalan-j2 # Because GNU jaxp_transform_impl doesn't work
  • After %setup, always remove any included jar or class files (if you haven't already). For example, use find with either -exec or xargs:
%{_bindir}/find . -type f -name "*.jar" | xargs %{__rm} -f
%{_bindir}/find . -type f -name "*.class" | xargs %{__rm} -f
  • After %build, you will usually do something like the following:
export CLASSPATH=$(build-classpath adaptx jdbc-stdext jndi jta junit ldapjdk oro regexp servletapi5 xerces-j2)
export OPT_JAR_LIST="ant/ant-nodeps ant/ant-trax jaxp_transform_impl"
%{ant} jar
%{ant} javadocs
  • The %install section usually has five parts (there is no such thing as %makeinstall in Java):
    • jars
    • javadocs
    • examples/demos
    • executable scripts
    • DOS end-of-line to Unix end-of-line conversion
# jar
%{__mkdir_p} %{buildroot}%{_javadir}
%{__install} -m 644 dist/%{name}-%{version}.jar %{buildroot}%{_javadir}/%{name}-%{version}.jar
(cd %{buildroot}%{_javadir} && for jar in *-%{version}.jar; do %{__ln_s} ${jar} `echo $jar | %{__sed} "s|-%{version}||g"`; done)

# javadoc
%{__mkdir_p} %{buildroot}{_javadocdir}/%{name}-%{version}
%{__cp} -a build/doc/javadoc/* %{buildroot}%{_javadocdir}/%{name}-%{version}

# examples (demo)
%{__mkdir_p} %{buildroot}%{_datadir}/%{name}/examples
%{__cp} -a build/examples/* %{buildroot}{_datadir}/%{name}/examples

# script
%jpackage_script org.exolab.castor.builder.SourceGenerator %{nil} %{nil} xerces-j2:%{name}

# fix end-of-line
%{__perl} -pi -e 's/\r$//g' src/etc/{CHANGELOG,LICENSE,README} \
  build/doc/*.{css,dtd,txt,xsd} build/doc/**/*.htm build/doc/ora-mar-2k/*.htm
  • For %post and %postun with javadocs, add:
%post javadoc
%{__rm_f} %{_javadocdir}/%{name}
%{__ln_s} %{name}-%{version} %{_javadocdir}/%{name}

%postun javadoc
if [ "$1" = "0" ]; then
    %{__rm} -f %{_javadocdir}/%{name}
fi
  • In the %files section, always use %defattr(0644,root,root,0755):
%files
%defattr(0644,root,root,0755)
%attr(0755,root,root) %{_bindir}/%{name}

%files demo
%defattr(0644,root,root,0755)
%{_datadir}/%{name}/examples

%files javadoc
%defattr(0644,root,root,0755)
%{_javadocdir}/%{name}-%{version}

%files manual
%defattr(0644,root,root,0755)
%doc build/doc/*

[edit] Additional rules for autoconf builds

export JAVA_HOME=%{java_home}
export JAR=%{jar}
export JAVA=%{java}
export JAVAC=%{javac}
export JAVADOC=%{javadoc}
%{configure2_5x}
%{make}

[edit] Manual RPM spec file modification for GCJ

  • Enable gcj support at the top of the spec file:
%define gcj_support 1

(note: %bcond_with would have been better)

  • Convert the noarch package to arch:
%if %{gcj_support}
Requires(post):   java-gcj-compat
Requires(postun): java-gcj-compat
BuildRequires:    java-gcj-compat-devel
%else
BuildArch: noarch
%endif
  • Modify the %install section:
%if %{gcj_support}
%{_bindir}/aot-compile-rpm
%endif
  • Modify the %files section:
%dir %{_libdir}/gcj/%{name}
%attr(-,root,root) %{_libdir}/gcj/%{name}/*
  • Modify the %post and %postun sections:
%if %{gcj_support}
%post
%{update_gcjdb}

%postun
%{clean_gcjdb}
%endif

[edit] Automatic RPM spec file modification for GCJ

In the future, this could be done automatically by RPM and supercede the manual method above.

Personal tools