0

I want to create a simple uber-jar for my non-modular project using shade. I followed the documentation at

[https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html]

but somehow, i keep getting this error:

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.4.1:shade (default) on project SharkTouch: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:3.4.1:shade for parameter transformers: Cannot load implementation hint 'org.example.Main'

here is my 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.example</groupId>
    <artifactId>SharkTouch</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>19</maven.compiler.source>
        <maven.compiler.target>19</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.10.1</version>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.reactfx</groupId>
            <artifactId>reactfx</artifactId>
            <version>1.4.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.4.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.example.Main">
                                    <mainClass>org.example.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
  • 2
    Study the resources in the [packaging section of the JavaFX tag](https://stackoverflow.com/tags/javafx/info). You cannot shade a jar with JavaFX components in the way you are doing it and expect that to work. – jewelsea Dec 25 '22 at 06:22
  • 1
    You are using selenium, which I have found does not currently work well in a modular project, so probably skip the jlink solutions in the link because they require a modular project. – jewelsea Dec 25 '22 at 06:28
  • 1
    See info on [shading JavaFX apps](https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing) if you really must. – jewelsea Dec 25 '22 at 06:30
  • @jewelsea thanks for the help man, i have studyied the topics. I did simplified my project and used the Main class without extending application like suggest on some stack overflow topics. Followed this topic but i still can't make shade to work.https://stackoverflow.com/questions/54063041/package-a-non-modular-javafx-application – Fernando Afonso Dec 25 '22 at 09:37
  • 1
    Selenium is a big complicated thing, it may not work with shading (I don’t know). Instead of shading [copy all of the dependencies to a lib directory](https://edencoding.com/runtime-components-error/#jar) and put the appropriate ones on the class path or module path. Use a script to run the app setting the path and zip everything up as a zip for distribution, just a suggestion. [jpackage, for example with JPackageScriptFX](https://github.com/dlemmermann/JPackageScriptFX) might be another option. – jewelsea Dec 25 '22 at 11:19
  • 1
    I don’t use shade but whatever you are doing with the [resource transformers](https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html) looks wrong and doesn’t match anything in the documentation that I can tell. – jewelsea Dec 25 '22 at 11:31
  • 1
    Note that JavaFX is platform-specific (more accurately, the native code it relies on is platform-specific). Creating a so-called uber/fat JAR file that is actually cross-platform would involve including the native code for each platform (which you _can_ do via Maven by manually defining JavaFX dependencies for each platform). And just like jewelsea, I don't know how Selenium reacts to being shaded. If you can, I would seriously consider using [jpackage](https://docs.oracle.com/en/java/javase/19/jpackage/packaging-overview.html). It works with non-modular projects (see `--input`). – Slaw Dec 25 '22 at 22:16
  • 1
    The link you posted in comments to documentation that you followed is broken. If you look at the examples in the link I provided, they all use implementations of preexisting transformers, whereas you link an implementation to your own `org.example.Main` class, which won’t be a transformer at all. Maybe you want this [ManifestTransformer](https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ManifestResourceTransformer), that can actually set the main class in the manifest. – jewelsea Dec 25 '22 at 23:40
  • Thanks man i will study more on the topic and find a way to distribute this without using shade, i believe you are right on that. – Fernando Afonso Dec 26 '22 at 00:27

0 Answers0