javamavenjlinkjpackagepicocli

Packaged a Java Application using Jpackage for ubuntu type deb. But giving error when type command (command not found)


I create A Java simple application and build jar using maven.

Main:

public class App {
    public static void main(String[] args) {
        System.out.println("come in");
        CommandLine commandLine = new CommandLine(new RootCommand());
        int executed = commandLine.execute(args);
        System.exit(executed);
    }
}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.rakib</groupId>
    <artifactId>test_jpackage</artifactId>
    <version>0.0.1</version>

    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
            <version>4.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20230618</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.9.0</version>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>info.picocli</groupId>
                            <artifactId>picocli-codegen</artifactId>
                            <version>4.7.5</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Then i create a native executable package and installer for ubuntu deb format using Jpackage.

command: jpackage --type deb --input . --name rakib --main-class org.rakib.App --main-jar target/test_jpackage-0.0.1.jar

when install this .deb package in my machine its installed (sudo dpkg -i rakib_1.0_amd64.deb). enter image description here

when run command in terminal rakib its can not to recognize.

enter image description here

How can i make this application like as linux command using jpackage?


Solution

  • The default creation of your package is meant to be installed in /opt in a folder of your package name.

    So, in your case, you should have a directory named /opt/rakib with a bin directory inside with your executable.

    To check where your package is going to be installed just type :

    $ dpkg --contents [your_package.deb]
    

    Using Jpackage, altough it's a valide DEB file, your executable is not directly linked to /usr/bin. So it's not on your PATH.

    I recommend to create a link into your ~/bin directory, which should be in your PATH.

    If you want to customize the target directory use --install-dir.