Generate rpm with redline (java) and maven 18 Jun 2015
A quick post as a simple tutorial to generate a rpm using redline and maven.
#Main
Simply create a Main class, inside the main method here is some basic info
public static void main(String[] args) throws NoSuchAlgorithmException, IOException, URISyntaxException
{
org.redline_rpm.Builder builder = new Builder();
File directory = new File(".");
builder.setType(RpmType.BINARY);
builder.setPlatform(Architecture.X86_64, Os.LINUX);
builder.setPackage("name", "1", "1");
builder.setDescription("Description");
builder.setSummary("Summary");
builder.build(directory);
}
You can add dependency on certain commands : example
builder.addDependencyMore("tar", "0");
builder.addDependencyMore("python", "0");
builder.addDependencyMore("wget", "0");
You can also add some pre-install script or post-install script and files too.
builder.setPostInstallScript(xxx);
File tarball = new File("/the/dir/of/your/file/file.tar.gz");
builder.addFile("/where/to/put/it/file.tar.gz", tarball);
#pom.xml
Specify jar for packaging. Then add the dependencies. In your pom you will need redline, slf4j and a logger.
<dependency>
<groupId>org.redline-rpm</groupId>
<artifactId>redline</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
To build an executable jar add the following plugin to your pom. Note the jar-with-dependencies
that will create a second jar with all the dependencies so that it will be easier to execute the jar
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>put.your.package.and.yourMainCLass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Run mvn clean install
this will create your jar in your target repository.
Go to the target directory.
#Generate the rpm
Launch
java -jar yourArtefact-with-dependencies.jar
This will create the rpm
Then to install the rpm (on linux), you may have to use sudo …
rpm -Uvh yourrpm.rpm
Now you can go on by adding some preInstall scripts for example !