0

I'm new to Gradle and finding the documentation confusing.

I've downloaded the Jaunt webscraping API, however I can't seem to add it to my project. When downloaded, Jaunt is a folder that contains the jauntx.x.x.jar file inside it as a root for the library. In a normal IntelliJ project, I would simply add a reference to that .jar file.

However, I'm using Gradle as this project requires being built into an executable jar

I need to add the Jaunt library to the project but if I do it the normal way my project recognises the library while I'm developing it but as soon as I try to run it, it tells me that the com.jaunt package is not found.

I assume that it needs to be added to the build.gradle file, however I'm not sure how.

Can anyone advise?

Build.gradle as follows:

plugins {
  id 'application'
  id 'org.openjfx.javafxplugin' version '0.0.8'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation files("libs/jaunt1.6.0.jar")
}

javafx {
    version = "14"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

jar {
    manifest {
        attributes 'Main-Class': 'org.openjfx.Main'
        attributes 'Class-Path': 'org/openjfx/ '
    }
}
application {
    mainClassName = 'org.openjfx.Main'
}
Ch-Webb
  • 1
  • 1
  • I think this might help you to include a local library in gradle https://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to-build-gradle-file – Michael Kreutz Apr 26 '20 at 19:46
  • @MichaelKreutz I added that snippet to build.gradle and copied the jaunt1.6.0 directory into the libs folder. Unfortunately, the new error is that the compiler can't seem to find :jaunt1.6.0, having looked directly in that folder and echoed the path of the jar file within it. Any idea? – Ch-Webb Apr 26 '20 at 20:05
  • can you update your question by adding your `build.gradle`? – Michael Kreutz Apr 26 '20 at 20:10
  • @MichaelKreutz Added – Ch-Webb Apr 26 '20 at 20:19
  • can you try to move the `jaunt1.6.0.jar` in folder `libs` and add `compile files('libs/jaunt1.6.0.jar)` to your dependencies. (You can also remove the flatDir section in this variant). If it does not work can you give an absolute path to the jar? – Michael Kreutz Apr 26 '20 at 20:41
  • @MichaelKreutz weirdly, all of my build folder has just disappeared. I'll try to regenerate it first – Ch-Webb Apr 26 '20 at 20:50
  • @MichaelKreutz unfortunately neither options working - build.gradle updated above – Ch-Webb Apr 26 '20 at 20:58
  • @MichaelKreutz - issue seems to be fixed. Updated build.gradle above with solution – Ch-Webb Apr 26 '20 at 21:07
  • Does this answer your question? [How to add local .jar file dependency to build.gradle file?](https://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to-build-gradle-file) – smac89 Apr 26 '20 at 21:09
  • @smac89 adding the dependency section as in build.gradle above doesn't immediately force a build error, however I am still unable to use anything from the imported library in my code itself - on build I receive error "package com.jaunt does not exist". Any idea? – Ch-Webb Apr 26 '20 at 21:12
  • Are you using an IDE? Did you refresh/update dependencies? What happens if you use sth from the library (e.g. add import statement) and run `gradle clean build` from a terminal? – Michael Kreutz Apr 27 '20 at 07:18
  • @MichaelKreutz developing in IntelliJ as a JavaFX project. It may be that i'm placing the jar file into the wrong area, as I originally had it in the build folder but am now reading that Gradle looks for /libs – Ch-Webb Apr 27 '20 at 09:10
  • @MichaelKreutz while doing the above has fixed my problem, I'm going to need to open a new question as the build seems unable to run – Ch-Webb Apr 27 '20 at 09:15

0 Answers0