Including javafx.util.Pair as a dependency in gradle - java

I have a springboot app that I developed using oracle JDK and it uses the javafx.util.pair class. When the jar built is run on a system with OpenJDK it cannot find this class. How can i package this dependency with my jar? I am using gradle. Here is my build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
}
}
description = "CF Service Broker using Java / Spring"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'cf-tile'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-devtools")
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('com.jayway.jsonpath:json-path')
testCompile group: 'junit', name: 'junit', version: '4.12'
}

I don't believe you can import javafx utils via gradle but you can, for platforms that do not include it in their version of OpenJDK, use openjfx.
For example you can install it in ubuntu using:
sudo apt-get install openjfx

Related

Facing issue while running gradle clean build

I am using Gradle 5 as my build tool for my Java application. I am getting below error while running gradle clean build.
Could not set unknown property 'stopPort' for root project '1-SimpleServlet' of type org.gradle.api.Project
PFA error image
Please find build.gradle file
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'jetty'
stopPort = 8081
stopKey = 'stopKey'
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
providedCompile 'org.apache.commons:commons-io:1.3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Pleas help me resolve this issue.
The jetty plugin has been deprecated with Gradle 3.0 and eventually been removed in Gradle 4.0 (Release Notes, Github Issue). Since you're using Gradle 5, I suggest to have a look at the official Building Java Web Applications guide which uses the gretty plugin.
Example build.gradle:
plugins {
id 'war'
id 'eclipse'
id 'org.gretty' version '3.0.1'
}
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
testCompile 'junit:junit:4.12'
}

Can't generate war - Java EE 8

After create a new Java EE project - in IntelliJ - new project -> Gradle from left list -> next -> next
I fill 2 files
build.gradle:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
group 'com.random'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
providedCompile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
and
#Path("/reservation")
public class ReservationWebService {
#GET
public Response listReservations() {
return Response.ok("hello").build();
}
}
now I'm trying to generate war by:
gradle war in terminal and I got:
'gradle' is not recognized as an internal or external command,
operable program or batch file.
How to generate war ?

How to setup Amazon Polly SDK with Gradle in IntetlliJ

I am trying to setup AWS Polly Java SDK with Gradle in IntelliJ by following this. I have already created a simple Spring Boot application using the spring intializr, so I added the items specified in the tutorial to my build.gradle file. When try to import
import com.amazonaws.services.polly.AmazonPollyClient
IntelliJ fails to resolve name polly.
This is my full build.gradle file
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'io.ai.vivid'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'com.amazonaws:aws-java-sdk-s3'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Also IntelliJ complains that it can't resolve the name manvenBom in my build.gradle. I have already tried SO solutions to this like invalidate cache/restart but could not resolve the issue.
I used your build.gradle file to replicate the issue and was able to import AmazonPollyClient after making the following changes to the dependencies
dependencies {
compile 'com.amazonaws:aws-java-sdk-s3'
compile group: 'com.amazonaws', name: 'aws-java-sdk-polly', version: '1.11.67'
The Gradle version used 4.8

NoClassDefFoundError for grizzly HTTP server

I am trying to execute a Grizzly HTTP Server inside a container.
Why i have this error, while running jar:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/grizzly/http/server/HttpServer
All was allright in maven with pom, but i met this error in gradle.
This is my build.gradle:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.13.0",
}
}
group 'com.mycompany'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.palantir.docker'
docker {
name "${project.group}/${jar.baseName}"
files 'build/libs'
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
jar {
manifest {
attributes 'Main-Class': 'com.mycompany.json_validator.Main'
}
baseName = 'JSON_validator-boot-docker'
version = '0.2.0'
archiveName = 'JSON_validator-boot-docker-0.2.0.jar'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.26'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '2.7'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.17'
compile group: 'org.glassfish.jersey', name: 'jersey-bom', version: '2.17', ext: 'pom'
}
All in all, i want to build jar for docker.
java.lang.NoClassDefFoundError:
org/glassfish/grizzly/http/server/HttpServer
NoClassDefFoundError indicates definition of the class could be found at the runtime, this could be missing jar/libraries. Make sure, you have included grizzly-http-server-x.x.x.jar and related jars in classpath.

Intellij-IDEA gradle templates

How can I change the template of "build.gradle" in IntelliJ IDEA 15.0.1 ?
I'd like to delete "sourceCompatibility", to add 'idea' plugin, and to modify the version of JUnit.
I'd tried to modify "Gradle Build Script" as below,
Perference > Editor > File and Code Templates > Gradle Build Script
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
but I got a build.gradle as followed
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
apply plugin: 'java'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Best Regards,
-Mitsutaka Ohisa
The preferences you are interest are hard-coded in IDEA JetBrains gradle plugin:
<IDEA_base>\plugins\gradle\lib\gradle.jar\org\jetbrains\plugins\gradle\frameworkSupport\GradleJavaFrameworkSupportProvider.class

Categories