what happend and What I want to do
I made a Springboot Project with spring initializr (https://start.spring.io/).
But I cannot executed built jar file with this error.
java -jar build/libs/spring302-0.0.1-SNAPSHOT-plain.jar
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at com.kaede.spring302.Spring302ApplicationKt.main(Spring302Application.kt)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 1 more
What should I do ?
I want to do this because I need to build to Docker Container.
How I made this project
I selected
Kotlin
Gradle 7.2
Spring 3.0.2
Java 17
And I used IntelliJ to build.
Project Name is spring302
NameSpace is com.kaede
1. Tried to Add Manifest Main-Class
java -jar build/libs/kotlin1-0.0.1-SNAPSHOT-plain.jar
Error: Could not find or load main class
First, I tried to just build, then happend this error.
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "com.kaede.spring302.Spring302Application"
}
}
So I added Manifest Main-Class in spring302/build.gradle.kts
java -jar build/libs/spring302-0.0.1-SNAPSHOT-plain.jar
Error: Main method not found in class com.kaede.spring302.Spring302Application,
please define the main method as:
public static void main(String[] args)
Then I got it is not Java Main Method Error.
2. Changed Main-Class to classNameKt
I changed Main-Class from Spring302Application to Spring302ApplicationKt
I heard Kotlin class will change classNameKt.java.
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "com.kaede.spring302.Spring302ApplicationKt"
}
}
So I changed my Main-Class .
java -jar build/libs/spring302-0.0.1-SNAPSHOT-plain.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
kotlin/jvm/internal/Intrinsics
at com.kaede.spring302.Spring302ApplicationKt.main(Spring302Application.kt)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 1 more
Then I got NoClassDefFoundError in Spring302ApplicationKt.main.
javap spring302-0.0.1-SNAPSHOT-plain/com/kaede/spring302/Spring302ApplicationKt.class
Compiled from "Spring302Application.kt"
public final class com.kaede.spring302.Spring302ApplicationKt {
public static final void main(java.lang.String[]);
}
Even my output has main.
3. Removed .m2/repository and rebuild
rm -rf ~/.m2/repository
I thought dependencies are complicated, So I removed all and re-build.
But things did not change.
what I expect
I can execute jar file
4. Changed Main Method from runApplication to SpringApplication.run
In main
runApplication<Spring302Application>(*args)
to
SpringApplication.run(Spring302Application::class.java, *args
But NoClassDefFoundError does not change
build.gradle.kts
This is my full dependencies.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "3.0.2"
id("io.spring.dependency-management") version "1.1.0"
kotlin("jvm") version "1.7.22"
kotlin("plugin.spring") version "1.7.22"
}
group = "com.kaede"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "com.kaede.spring302.Spring302ApplicationKt"
}
}
Related
At the start of the application I am spotting three warnings:
Java HotSpot(TM) 64-Bit Server VM warning: Option AllowRedefinitionToAddDeleteMethods was deprecated in version 13.0 and will likely be removed in a future release.
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
But its only warning. Unfortunately I am getting errors aswell:
ERROR i.o.javaagent.tooling.HelperInjector - Error preparing helpers while processing class org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter for spring-webflux. Failed to inject helper classes into instance org.springframework.boot.loader.LaunchedURLClassLoader#64b31700
java.lang.UnsupportedOperationException: Cannot get defined package using reflection: Unsupported class file major version 61
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2022-02-25 12:30:22.226Z ERROR i.o.javaagent.tooling.HelperInjector - Error preparing helpers while processing class reactor.blockhound.shaded.net.bytebuddy.dynamic.loading.InjectionClassLoader for classloader. Failed to inject helper classes into instance org.springframework.boot.loader.LaunchedURLClassLoader#bae47a0
java.lang.UnsupportedOperationException: Cannot get defined package using reflection: Unsupported class file major version 61
ERROR i.o.javaagent.tooling.HelperInjector - Error preparing helpers while processing class org.apache.http.impl.client.CloseableHttpClient for apache-httpclient. Failed to inject helper classes into instance org.springframework.boot.loader.LaunchedURLClassLoader#64b31700
java.lang.UnsupportedOperationException: Cannot get defined package using reflection: Unsupported class file major version 61
at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Initializable$Unavailable.getDefinedPackage(ClassInjector.java:442)
at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.injectRaw(ClassInjector.java:218)
at io.opentelemetry.javaagent.tooling.HelperInjector.injectClassLoader(HelperInjector.java:205)
at io.opentelemetry.javaagent.tooling.HelperInjector.transform(HelperInjector.java:137)
at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10364)
at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10302)
at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1600
In the project I am using Azure KeyVault, and BlockHound to communicate with that.
Application.java
#SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
BlockHound
.builder()
.allowBlockingCallsInside(KeyVaultClient.class.getName(), "getSecret")
.allowBlockingCallsInside(ManagedIdentityCredential.class.getName(), "getToken")
.install();
SpringApplication.run(MyApplication.class, args);
}
}
I have added -XX:+AllowRedefinitionToAddDeleteMethods to the VM options in IntelliJ.
I have also added it to the gradle.build file, but it seems to not work properly.
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '2.5.10'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'pmd'
id 'checkstyle'
id 'com.github.spotbugs' version '4.7.2'
id 'com.github.ben-manes.versions' version '0.39.0'
id 'io.freefair.lombok' version '5.3.3.3'
id 'com.gorylenko.gradle-git-properties' version '2.3.1'
id 'com.coditory.integration-test' version '1.3.0'
}
apply from: 'gradle/jacoco.gradle'
apply from: 'gradle/spotbugs.gradle'
group = 'my.group'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
jar {
enabled = false
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', '2020.0.3')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom 'com.azure.spring:azure-spring-cloud-dependencies:2.13.0'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.cloud:spring-cloud-starter'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
implementation 'org.zalando:logbook-spring-boot-starter:2.14.0'
implementation group: 'org.zalando', name: 'logbook-spring-boot-webflux-autoconfigure', version: '2.11.0'
implementation 'io.projectreactor.tools:blockhound:1.0.6.RELEASE'
implementation 'com.azure.spring:azure-spring-cloud-appconfiguration-config'
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok-mapstruct-binding:0.2.0'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'net.javacrumbs.json-unit:json-unit-assertj:2.28.0'
}
springBoot {
buildInfo()
}
lombok {
version = '1.18.20'
}
pmd {
toolVersion = '6.33.0'
ruleSets = []
ruleSetConfig = rootProject.resources.text.fromFile('config/pmd/ruleset.xml')
sourceSets = [sourceSets.main]
consoleOutput = true
ignoreFailures = true
}
checkstyle {
toolVersion = '8.41.1'
config = rootProject.resources.text.fromFile('config/checkstyle/checkstyle.xml')
showViolations = false
checkstyleTest.enabled = false
checkstyleIntegration.enabled = false
}
tasks.withType(Test) {
useJUnitPlatform()
testLogging {
events = ['passed', 'failed', 'skipped']
exceptionFormat = 'full'
}
// this one is needed for blockhound to work in tests
jvmArgs('-XX:+AllowRedefinitionToAddDeleteMethods')
}
bootRun {
// this one is needed for blockhound to work
jvmArgs('-XX:+AllowRedefinitionToAddDeleteMethods')
args = ['--spring.profiles.active=native']
}
docker.entrypoint:
#!/bin/bash
exec java -Djava.security.egd=file:/dev/./urandom \
-XX:+AllowRedefinitionToAddDeleteMethods \
-XX:+UseG1GC \
-XX:MaxRAMPercentage=70 \
-XX:+PrintFlagsFinal \
-XshowSettings:vm \
-javaagent:/opt/myapp/agent.jar \
-jar /opt/myapp/myapp.jar
I am using: Java 17.0.2 and gradle 7.3
I have already tried changing spring.profiles.active to native, local etc. I have also migrated project from Java 16 to 17, and from gradle 7.1 to 7.3, other dependencies aswell. I am having issues with springboot in version 2.6.4, but possibly I should raise cloud dependencies' versions, but not sure how are they compatible with each other.
The solution is working fine, I am obtaining properties from KeyVault as expected.
I want to get rid off those warnings, but I am out of ideas at the moment. Maybe somebody had similiar situation?
(copy from my GitHub issue: https://github.com/spring-projects/spring-boot/issues/22955)
I noticed that Java's ServiceLoader mechanism doesn't work in packaged Spring Boot apps.
Background
I've tried to use javax.script.ScriptEngineManager which relies on ServiceLoaders. I was able to successfully launch the app from the IDE but not from the command line.
Repro
// build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '2.3.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
}
tasks.withType(JavaCompile) {
options.release.set(11) // required Gradle >= 6.6
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.python:jython-slim:2.7.2'
}
// Main.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.script.ScriptEngineManager;
import java.util.Objects;
#SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
var engine = new ScriptEngineManager().getEngineByName("python");
Objects.requireNonNull(engine);
System.out.println("success");
}
}
It is possible to launch this from the IDE (IntelliJ in my case) but not via the command line:
gradle bootJar && java -jar build/libs/XXX.jar
Temporary workaround
Instead of using the ScriptEngineManager it is possible to directly use Jython's ScriptEngine implementation:
var engine = new org.python.jsr223.PyScriptEngineFactory().getScriptEngine();
The ServiceLoader mechanism is correctly finding PyScriptEngineFactory. The problem is then a silent failure when it attempts to create a script engine from it. Unfortunately, when you call getEngineByName(String), ScriptEngineManager swallows any exception thrown by getScriptEngine():
try {
ScriptEngine engine = spi.getScriptEngine();
engine.setBindings(getBindings(), ScriptContext.GLOBAL_SCOPE);
return engine;
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
Your work around doesn't work for me, but that's useful as it allows me to see the exception swallowed by ScriptEngineManager. It is the following:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
at java.io.File.<init>(File.java:418)
at org.python.core.PrePy.getJarFileNameFromURL(PrePy.java:427)
at org.python.core.PrePy._getJarFileName(PrePy.java:362)
at org.python.core.PrePy.getJarFileName(PrePy.java:345)
at org.python.core.PySystemState.doInitialize(PySystemState.java:1195)
at org.python.core.PySystemState.initialize(PySystemState.java:1130)
at org.python.core.PySystemState.initialize(PySystemState.java:1085)
at org.python.core.PySystemState.initialize(PySystemState.java:1080)
at org.python.core.PySystemState.initialize(PySystemState.java:1075)
at org.python.core.PySystemState.initialize(PySystemState.java:1070)
at org.python.core.PySystemState.<init>(PySystemState.java:207)
at org.python.util.PythonInterpreter.threadLocalStateInterpreter(PythonInterpreter.java:80)
at org.python.jsr223.PyScriptEngine.<init>(PyScriptEngine.java:27)
at org.python.jsr223.PyScriptEngineFactory.getScriptEngine(PyScriptEngineFactory.java:85)
at com.example.demo.Gh22955Application.main(Gh22955Application.java:11)
... 8 more
PrePy is making some assumptions about jar:file: URLs that don't hold true in a Spring Boot fat jar. Spring Boot provides an escape hatch for this, allowing a jar file to be automatically unpacked from the fat jar when it's launched. In this case, it's the jython-slim jar that needs to be unpacked. To do that, add the following to your build.gradle:
bootJar {
requiresUnpack "**/jython-slim*"
}
It's been 3 days that I look on the internet how to fix this on gradle
Caused by: java.lang.IllegalAccessError: class com.jfoenix.skins.JFXTabPaneSkin (in module com.jfoenix) cannot access class com.sun.javafx.scene.control.behavior.TabPaneBehavior (in module javafx.controls) because module javafx.controls does not export com.sun.javafx.scene.control.behavior to module com.jfoenix
On simple idea projects I was adding
--add-exports javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix --add-exports javafx.controls/com.sun.javafx.scene.control=com.jfoenix --add-exports javafx.base/com.sun.javafx.binding=com.jfoenix --add-exports javafx.graphics/com.sun.javafx.stage=com.jfoenix --add-exports javafx.base/com.sun.javafx.event=com.jfoenix
I know, I have to add jvm options but how do I ?
I'm using gradle javafx 11.0.2, java 11, on intellij idea,
this is the build.gradle
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
compileJava.options.encoding = 'UTF-8'
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/com.jfoenix/jfoenix
compile group: 'com.jfoenix', name: 'jfoenix', version: '9.0.9'
compile group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.7.0-9.1.2'
// https://mvnrepository.com/artifact/de.jensd/fontawesomefx-commons
runtime group: 'de.jensd', name: 'fontawesomefx-commons', version: '9.1.2'
// https://mvnrepository.com/artifact/com.h2database/h2
compile group: 'com.h2database', name: 'h2', version: '1.4.199'
}
javafx {
version = "11.0.2"
modules = [ 'javafx.controls', 'javafx.fxml','javafx.graphics','javafx.base' ]
}
mainClassName = 'org.yanisboukir.agence.Main'
Thanks
If you are running a non modular project (you don't have module-info.java), to include the VM arguments in your run task, all you need to add to your build.gradle file is:
run {
jvmArgs = [
"--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED",
"--add-exports=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED",
"--add-exports=javafx.base/com.sun.javafx.binding=ALL-UNNAMED",
"--add-exports=javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED",
"--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED"
]
}
Note that in this case, you can't use --add-exports=...=com.jfoenix.
If you run a modular project, with a module descriptor like:
module hellofx {
requires javafx.controls;
requires javafx.fxml;
requires com.jfoenix;
opens org.openjfx to javafx.fxml;
exports org.openjfx;
}
now these are the VM arguments that you will have to include in your build file:
run {
jvmArgs = [
"--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
"--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
"--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
"--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
"--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix"
]
}
For newer versions of Gradle (6.x) the following worked for me:
compileJava {
options.compilerArgs.add('--add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED')
}
For Java test code:
compileTestJava {
options.compilerArgs.add('--add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED')
}
Compile-time following:
compileJava {
options.compilerArgs.add('--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix')
options.compilerArgs.add('--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix')
options.compilerArgs.add('--add-exports=--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix')
options.compilerArgs.add('--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix')
}
Run-time following
run {
jvmArgs = [
"--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
"--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
"--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
"--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix"
]
}
We must set both of them. If we only set the first one idea can compile, however at the run time throw exception. Thanks #sakra #José Pereda
this didn't work for me in JDK 16:
run {
jvmArgs = [
"--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
"--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
"--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
"--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
"--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
]
}
what worked instead is
run {
jvmArgs = [
"--add-opens=java.base/java.lang.reflect=com.jfoenix",
"--add-opens=java.base/java.lang.reflect=com.jfoenix",
"--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
"--add-opens=javafx.base/com.sun.javafx.binding=com.jfoenix",
"--add-opens=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
"--add-opens=javafx.base/com.sun.javafx.event=com.jfoenix",
]
}
Project structure (full project can be downloaded here):
Launcher.java class:
import org.sikuli.script.Pattern;
public class Launcher {
public static void main(String[] args)
{
Pattern p1 = new Pattern(Launcher.class.getResource("sample.png"));
}
}
build.gradle file:
plugins {
id 'java'
}
group 'com.myproj'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
url "http://oss.sonatype.org/content/groups/public"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.sikulix', name: 'sikulixapi', version: '1.1.4-SNAPSHOT'
}
Program throws following runtime error:
loadlib: opencv_java342.dll not in any libs folder
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.sikuli.script.Pattern.<init>(Pattern.java:125)
at Launcher.main(Launcher.java:7)
Caused by: java.lang.RuntimeException: Sikulix fatal error: loadlib: opencv_java342.dll not in any libs folder
at org.sikuli.script.Sikulix.terminate(Sikulix.java:58)
at org.sikuli.script.RunTime.terminate(RunTime.java:60)
at org.sikuli.script.RunTime.libsLoad(RunTime.java:915)
at org.sikuli.script.RunTime.loadLibrary(RunTime.java:1105)
at org.sikuli.script.Finder2.<clinit>(Finder2.java:33)
... 2 more
Disconnected from the target VM, address: '127.0.0.1:9172', transport: 'socket'
Process finished with exit code 1
Interesting thing is that my code worked in the morning smoothly. And when I got back home in the evening something went wrong. Can't run it anymore.. Thank you for any help!
What I've tried:
reload sikulixapi package using Gradle from scratch
download 3.4.2 opencv and load it in runtime like suggested here
add opencv_java342.dll directly to the project as described here
even tried to launch the project on different Windows machine to exclude environment issues - still fails
It happened, that there was a bug in the latest snapshot. Full conversation with developers can be found here.
So, in this situation you have at least two options:
Wait until developers fix the issue and introduce new snapshot. Bugs/questions can be reported here.
Tell gradle/maven to use previous stable version of sikulixapi
library. Full list of currently available snapshots can be found here. Gradle example:
dependencies {
compile group: 'com.sikulix', name: 'sikulixapi', version: '1.1.4-20181214.081346-62'
}
I need to add default JVM options to my jar, when build with Gradle.
From the documentation I got that I have to set:
applicationDefaultJvmArgs = ["-Djavafx.embed.singleThread=true"]
I have not much experience with Gradle and the developer that wrote the build.gradle file wrote it different from what most websites give as examples.
Here is the build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
version = '0.1'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'placeholder'
}
task release(type: Jar) {
manifest {
attributes("Implementation-Title": "placeholder",
"Implementation-Version": version,
'Main-Class': 'placeholder.Application')
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
I don't know where to put the arguments. I tried putting them in different locations, but I always get:
A problem occurred evaluating root project 'placeholder'.
> No such property: applicationDefaultJvmArgs for class: org.gradle.api.tasks.bundling.Jar_Decorated
Much Thanks,
Jhonny
From the top of my head I can think of 2 options:
Option1: Do what #Ethan said, it'll likely work:
package placeholder;
//your imports
public class Application{
static {
System.getProperties().set("javafx.embed.singleThread", "true");
}
// your code
public static void main(String... args){
//your code
}
}
Option 2: Use the application plugin + default jvm values
build.gradle:
apply plugin: 'application'
//your code
applicationDefaultJvmArgs = ["-Djavafx.embed.singleThread=true"]
Now you can run your code 2 ways:
From gradle
$gradle run
From distribution(script). from the generated script that the application plugin will provide:
$gradle clean build distZip
Then gradle will generate a zip file somewhere under ${your.projectdir}/build. Find the zip then unzip it and under /bin you'll find a ${yourproject}.bat and ${yourproject} executables. One is for Linux/mac/unix (${yourproject}) the other one is for windows (${yourproject.bat})
Option 3 (Android Developer): Use gradle.properties to set jvm argument
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# You can setup or customize it according to your needs and combined with the above default value.
org.gradle.jvmargs=-Djavafx.embed.singleThread=true
For more info on how to use gradle build environment on docs.gradle.org
applicationDefaultJvmArgs is provided by the Application plugin. So if you apply that plugin, the error would probably go away, and you should be able to execute the program by issuing gradle run once you set the mainClassName property to the fully qualified class name, the main method of which you want to invoke.
Using a local gradlew is the easiest.
Just append to DEFAULT_JVM_OPTS.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m" "-XX:+AllowRedefinitionToAddDeleteMethods"'
you can use command-line with gradle task:
class AppRun extends JavaExec {
private boolean withDebug
#Option(option = "with-debug", description = "enable debug for the process. ")
public void setDebugMode(boolean debug) {
this.withDebug = debug
}
public boolean getDebugMode() {
return this.withDebug
}
}
task run(type: AppRun) {
}
then run task with options
gradle run --with-debug
set this to Your java main Class.
static {
System.setProperty("nashorn.args", "--no-deprecation-warning");
}