Я делаю javafx-приложение с gradle, но оно дает мне предупреждение: произошла недопустимая операция отражающего доступа, когда я запускаю ее как jar, и InaccessibleObjectException, когда я запускаю ее как задачу gradle:
Jar:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.fasterxml.jackson.databind.util.ClassUtil (file:/C:/Users/i/Downloads/fda.das.main.jar) to field javafx.scene.image.Image.url
WARNING: Please consider reporting this to the maintainers of com.fasterxml.jackson.databind.util.ClassUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Задача Gradle:
java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.String javafx.scene.image.Image.url accessible: module javafx.graphics does not "opens javafx.scene.image" to unnamed module @717d2ad8
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:176)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:170)
at com.fasterxml.jackson.databind.util.ClassUtil.checkAndFixAccess(ClassUtil.java:914)
at com.fasterxml.jackson.databind.deser.impl.FieldProperty.fixAccess(FieldProperty.java:102)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBuilder._fixAccess(BeanDeserializerBuilder.java:484)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBuilder.build(BeanDeserializerBuilder.java:350)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:246)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:137)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:411)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findNonContextualValueDeserializer(DeserializationContext.java:467)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:473)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:477)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4190)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4009)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3004)
at Helpers.Services.LoginService$1.call(LoginService.java:59)
at Helpers.Services.LoginService$1.call(LoginService.java:32)
at javafx.graphics/javafx.concurrent.Task$TaskCallable.call(Task.java:1425)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at javafx.graphics/javafx.concurrent.Service.lambda$executeTask$6(Service.java:725)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/javafx.concurrent.Service.lambda$executeTask$7(Service.java:724)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Когда я запускаю его из intellij, все работает нормально. Я попытался добавить "--add-opens", "java .base / jdk.internal.loader = ALL-UNNAMED" в мой gradle.build как после плагина, так и во время выполнения {}, но это не помогло it:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
apply plugin: 'application'
applicationDefaultJvmArgs = ["--add-opens", "java.base/jdk.internal.loader=ALL-UNNAMED"]
run {
main = 'Application.RestaurantApplication'
applicationDefaultJvmArgs = ["--add-opens", "java.base/jdk.internal.loader=ALL-UNNAMED"]
}
group 'fda'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'org.json', name: 'json', version: '20180813'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'com.1stleg', name: 'jnativehook', version: '2.1.0'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.3'
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.8'
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.media' ]
}
Есть идеи, что здесь не так и почему не работает загрузчик без имени?
Мой код javaFX - это служба, которая запрашивает логин пользователя, возникает ошибка, когда я использую картограф с моим json контентом для создания пользовательской модели, в которой есть поле изображения javafx:
public class LoginService extends Service {
private final StringProperty username = new SimpleStringProperty(this, "username");
private final StringProperty password = new SimpleStringProperty(this, "password");
public final StringProperty usernameProperty() { return username; }
public final StringProperty passwordProperty() { return password; }
@Override
protected Task createTask() {
return new Task<User>() {
@Override
protected User call() throws Exception {
Map<String, Object> jsonValues = new HashMap<>();
jsonValues.put("username", username.get());
jsonValues.put("password", password.get());
JSONObject json = new JSONObject(jsonValues);
StringEntity postEntity = new StringEntity(json.toString(), "UTF8");
postEntity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
HttpPost httpPost = new HttpPost( base + "/api/users/login");
httpPost.setEntity(postEntity);
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
int responseStatus = response.getStatusLine().getStatusCode();
HttpEntity receivedEntity = response.getEntity();
String content = EntityUtils.toString(receivedEntity);
if (responseStatus != 200) {
EntityUtils.consume(receivedEntity);
throw new HttpException(content);
}
String jwtToken = response.getHeaders("Authorization")[0].getValue();
User user = mapper.readValue(content, User.class); //Here
ServerRequests.userPreference.put(String.valueOf(user.getId()), jwtToken);
EntityUtils.consume(receivedEntity);
return mapper.readValue(content, User.class);
}
}
};
}
}
И моя модель:
package Models;
import javafx.scene.image.Image;
import java.util.LinkedHashMap;
import java.util.Map;
public class User {
private int id;
private String username;
private String firstName;
private String lastName;
private int age;
private String country;
private String role;
private String profilePicture;
private Restaurant restaurant;
private Image image;
private Map<Integer, Order> orders = new LinkedHashMap<>();
public User(){
}
public User(int id, String username, String firstName, String lastName, int age, String country, String role, String profilePicture, Restaurant restaurant) {
this.id = id;
this.username = username;
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.country = country;
this.role = role;
this.profilePicture = profilePicture;
this.restaurant = restaurant;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getProfilePicture() {
return profilePicture;
}
public void setProfilePicture(String profilePicture) {
this.profilePicture = profilePicture;
}
public Restaurant getRestaurant() {
return restaurant;
}
public void setRestaurant(Restaurant restaurant) {
this.restaurant = restaurant;
}
public Map<Integer, Order> getOrders() {
return orders;
}
public void setOrders(Map<Integer, Order> orders) {
this.orders = orders;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
}