0

When I try to connect API keys to a given app, the app crashes and I get the following error:

java.lang.reflect.InaccessibleObjectException: Unable to make field private static volatile java.net.Authenticator java.net.Authenticator.theAuthenticator accessible: module java.base does not "opens java.net" to unnamed module @6f1eab88

I now realize that I need to "build a specific binary (JAR) for my platform." I have been trying for a couple hours but truthfully have no idea what to do. Any help would be appreciated.

Specs:

MacOS Big Sur v11.6.8

Java v17.0.5

Gradle v7.6

Homebrew v3.6.16

GitHub link to project: https://github.com/quantverse/ptltrader

Instructions for building are in the "README.md" file.

I normally run the JAR file via terminal and it works fine until I try connecting to the website via API, at which point the app crashes. When I try to run any Gradle functions, nothing works because it's a JAR file.

I downloaded the .zip file and tried to run Gradle again but got several errors. I believe these are due to the code being written in 2012 and therefore being outdated. After replacing a couple lines of code as recommended by stackoverflow (such as "testImplementation" instead of "testCompile," and "doLast" instead of "<<"), I try running gradle ./gradlew run as recommended by the source code, and get the following error:

Task './gradlew' not found in root project 'PTLTrader'.

When I try gradle run, I get the following error:

> Process 'command '/usr/local/Cellar/openjdk@17/17.0.5/libexec/openjdk.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

At this point, I gave up because I did not know what else I could do. I tried moving the JAR file into the directory to run it with the rest of the zip file, but the same error/inability to connect to website API occurred.

  • Try running `./gradlew run`, not `gradle ./gradlew run`. The project is using an older version of Gradle (4.4), so `gradle --version` and `./gradlew --version` are probably different. [Gradle 4.4 only supports Java 9](https://docs.gradle.org/7.6/userguide/compatibility.html#java), so if you have a higher Java version on your classpath (run `java --version` to check), you'll need to downgrade (since you're on MacOS, you could use [jEnv](https://github.com/jenv/jenv) to manage different Java versions per project). – aSemy Dec 24 '22 at 14:01
  • Running `./gradlew run` gives the following error: `Could not determine java version from '17.0.5'.` Indeed, I have a higher Java version so I will attempt to downgrade and come back with an update. Thank you! – Sahil Sidhu Dec 24 '22 at 14:06
  • @aSemy I used this link to set Java to v1.8.0_351-b10: https://stackoverflow.com/questions/46513639/how-to-downgrade-java-from-9-to-8-on-a-macos-eclipse-is-not-running-with-java-9 . I attempted `./gradlew run` again, and I got much more compilation then normal (got up to 100% I believe). However, I received the following error: `Execution failed for task ':compileJava'. > Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.` I have javac 17.0.5 - Do I need to downgrade this as well? – Sahil Sidhu Dec 24 '22 at 14:13

1 Answers1

1

I cloned your repo and could succesfully build, like this:

In gradle-wrapper.properties inside Project/gradle/wrapper i changed the local distributionUrl of that project to:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip (other versions like gradle-5.1.1-bin.zip should also work, but didn't test.

Ran a task once again with./gradlew build and got this error:

Could not find method leftShift() for arguments [build_77lj9mcapfpzvdg4mdx64jy00$_run_closure7@5775175c] on task ':swtDiag' of type org.gradle.api.DefaultTask.

Went to Project/build.gradle and removed << on task swtDiag which was deprecated on version 5.0:

It looks like this now:

task swtDiag  {
    println 'archSpec: ' + archSpec
    println 'swtWindowingLibrary: ' + swtWindowingLibrary
    println 'swtArch: ' + swtArch
    println 'swtPlatform: ' + swtPlatform
    
}

BUILD SUCCESSFUL in 1m 21s
3 actionable tasks: 3 executed

P.S: make sure to use ./gradlew run. This is your project-specific gradle config instead of the system-wide. (both ./gradlew build or ./gradlew run worked fine.

References:

documentation about the error of my failed build

distributionUrl mismatch

!!! As the github README.md documentation suggests, you need to use an older JDK version.

See: https://github.com/quantverse/ptltrader#prerequisites

aamdevsecops
  • 104
  • 8
  • Hello, thank you for your message. I tried out your steps and was able to get a lot of compilation. The code ran for 1m 21s, then failed. This was the error: `Execution failed for task ':compileJava'. > Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.` (1 actionable task: 1 executed) When I run `javac -version`, I see that it is v17.0.5 - do I need to downgrade this to v8 as well? I am having difficulty finding how to do this online, since `java -version` returns what is expected (1.8.0_351-b10) – Sahil Sidhu Dec 24 '22 at 14:40
  • `/usr/libexec/java_home -V | grep jdk` should give you the actual version used. And then you can export it as a path in your .zsh env. Otherwise, if you're using an IDE such as intelliJ, you can specify the JDK in your Build Tools Settings: File > Settings > Build Tools > Gradle – aamdevsecops Dec 24 '22 at 14:49
  • I've been trying to export to a lower JDK by using the method used in this website: https://mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/#java-home-and-macos-11-big-sur . However, I get this error: `zsh: permission denied: /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home` – Sahil Sidhu Dec 24 '22 at 15:04