Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwing error while fatJaring using gradle #237

Open
Reqeique opened this issue Aug 12, 2022 · 9 comments
Open

Throwing error while fatJaring using gradle #237

Reqeique opened this issue Aug 12, 2022 · 9 comments

Comments

@Reqeique
Copy link

Reqeique commented Aug 12, 2022

I was currently experimenting with pi4j but when I start to fat Jar it, it kept throwing exception
my first attempt was to utilize shadowJar, which wasn't able to jar all the necessary libraries resulting lib wasn't found exception
so I put all the necessary jar files manually but gave Method [create([class java.lang.Integer])] could not be resolved in provider [pigpio-digital-output(com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl)]; Overridden instances of 'create()' are not supported unless defined as default methods in the provider interface
following that I tried my third attempts which was to utilize built in jaring method using the following code

task("fatJar", type = Jar::class){

    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
        attributes(mapOf("Main-Class" to "myClass"))
    }
    from(configurations.runtimeClasspath.get().map{ if
            (it.isDirectory) it else zipTree(it) })
    with(tasks["jar"] as CopySpec)
}

but throws the same execption no luck!
Note: the code i used was from https://pi4j.com/documentation/io-examples/digital-output/ which was then converted to kotlin

@taartspi
Copy link
Collaborator

taartspi commented Aug 14, 2022

One thing, use this as the example of code. I believe once your present code creates and runs through the fat, it will not change the LED. https://github.com/Pi4J/pi4j-example-minimal

I created a clone of this example successfully ran it.

FAT used info from https://pi4j.com/documentation/building/fat-jar/ and example https://github.com/Pi4J/pi4j-example-fatjar to copy the needed edits to the pom file.

I edited the pom file to add the FAT specific details . Was able to: mvn clean package, cd into target/distribution and sudo java -jar pi4j-example-fatjar.jar

Give me a minute and I will attach my pom

hope this help. Tom

@taartspi
Copy link
Collaborator

pom.txt

@taartspi
Copy link
Collaborator

I could see you prefer gradle to build. I used the example testcase from above and added gradle to it. I see an error. I normally use maven so all this is a matter of digging and I have not found an answer. I do see that running under gradle build there are fewer providers loaded.

Maven these output providers.
├─DIGITAL_OUTPUT: [3] <com.pi4j.io.gpio.digital.DigitalOutputProvider>
│ ├─PROVIDER: "PiGpio Digital Output (GPIO) Provider" {pigpio-digital-output} <com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl> {com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl}
│ ├─PROVIDER: "LinuxFS Digital Output (GPIO) Provider" {linuxfs-digital-output} <com.pi4j.plugin.linuxfs.provider.gpio.digital.LinuxFsDigitalOutputProviderImpl> {com.pi4j.plugin.linuxfs.provider.gpio.digital.LinuxFsDigitalOutputProviderImpl}
│ └─PROVIDER: "RaspberryPi Digital Output (GPIO) Provider" {raspberrypi-digital-output} <com.pi4j.plugin.raspberrypi.provider.gpio.digital.RpiDigitalOutputProviderImpl> {com.pi4j.plugin.raspberrypi.provider.gpio.digital.RpiDigitalOutputProviderImpl}
├─I

Using gradle only
└─PROVIDER: "RaspberryPi Digital Output (GPIO) Provider" {raspberrypi-digital-output} <com.pi4j.plugin.raspberrypi.provider.gpio.digital.RpiDigitalOutputProviderImpl> {com.pi4j.plugin.raspberrypi.provider.gpio.digital.RpiDigitalOutputProviderImpl}

My error is
Exception in thread "main" com.pi4j.provider.exception.ProviderNotFoundException: Pi4J provider [pigpio-digital-output] c

Was this your initial error when you said a 'lib' was not found ?

@Reqeique
Copy link
Author

Reqeique commented Aug 20, 2022

@taartspi that was absolutely the error that I faced while fatJaring for the first time but was resolved easily(not considering the last exception)

@RLEO94
Copy link

RLEO94 commented Sep 27, 2022

Hi did you solve this problem?

I got the same exception. If I run my code on my computer in Intellij IDEA with the Embedded Linux JVM plugin, then the code works well (GPIO Out turns HIGH and Input is detected, ecc..).

If I create a fatjar with gradle, copy the file to my RPI4 and execute it with java -jar, then I got the same exception (Provider not found).
On the webside is described how to create a fat jar with Maven: https://pi4j.com/documentation/building/fat-jar/.
So I try now to use this plugin: https://github.com/dkorotych/gradle-maven-exec-plugin
with the goal to execute the described maven commands/plugins through gradle, but I'm still struggling

@Reqeique
Copy link
Author

Reqeique commented Sep 27, 2022

@RLEO94 for Provider not found you could easily tweak it by modifying the fatjar to include the the library that wasn't found manually by using tools like win-rar or creating custom jaRing method as above(that was taken from here
) to include all dependencies

overall can't guarantee wouldn't throw Method [create([class java.lang.Integer])] could not be resolved in provider

@RLEO94
Copy link

RLEO94 commented Sep 28, 2022

Hi
Thanks for your help. I will give it a try :)

@charbelmkh
Copy link

Hey @Reqeique, I'm not sure if you were able to solve this issue, but I managed to solve it by checking out
pi4j-kotlin & using shadow plugin & configuring the below gradle task

tasks.named("shadowJar", ShadowJar::class.java) {
    mergeServiceFiles()
    manifest.attributes["Main-Class"] = "MinimalExampleKt"
}

@bennymeg
Copy link

bennymeg commented Jun 6, 2024

This is worth including in the docs alongside the maven Uber Jar document.
More information can be found in shadow: merging-service-descriptor-files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants