I'm using OpenJDK 11 and OpenJFX 11.0.1 with Gradle in IntelliJ IDEA for my project.
When I use javafx.base module, IntelliJ IDEA reports an error at line 1 (project module declaration) saying I'm not including the javafx.beans module (beans is a package in javafx.base module) in my module requirements.
Gradle jar task executes without any errors or warnings so this error is likely related to IntelliJ IDEA.
Error message: "Module 'hr.caellian.lunar' reads package 'javafx.beans' for both 'javafx.base' and 'javafx.base'"
If I remove 'javafx.base' requirement, 'javafx.base' from above error is replaced with the next javafx module.
I'm also getting a warnings at javafx module requirement lines: "Ambiguous module reference: javafx.base" for 'javafx.base' and so on for each javafx module.
Here's my module-info.java file:
module hr.caellian.lunar {
requires java.base;
requires kotlin.stdlib;
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
opens hr.caellian.lunar.gui to javafx.graphics;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.iconli.core;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.dataformat.yaml;
requires arglib;
requires org.apache.bcel;
}
I looked online for a solution for at least half an hour now. All I found was a website saying only the modules I already included are necessary for JFX (which was for JavaFX 9 I think).
I redownloaded JavaFX modules to see if I missed copying something but I didn't - javafx.beans module doesn't exist.
'java --list-modules' doesn't list any javafx modules if that's a problem, although I gathered that it should only list jdk modules and OpenJFX is no longer included with OpenJDK.
I installed OpenJFX SDK into JDK folder (lib files copied to lib folder, same for legal), added javafx jar dependency files from lib folder of JDK11 in IDEA manually. I also added all jmod files to jmod folder of JDK11.
Is it possible JavaFX modules have bad module-info.java files or something like that? Is this IntelliJ IDEA bug?
Managed to fix the problem thanks to the comment from #nullpointer.
The problem was that I had copied files from JavaFX SDK to both my JDK 11 classpath and project lib folder.
If you're seeing this error with the same warnings that means you probably have duplicate module jars (maybe in future modules directly) in your IntelliJ project JDK Classpath and in your build.gradle (or lib folder).
How to fix:
I removed OpenJFX SDK jars from JDK11 Classpath in IntelliJ IDEA in Project Structure. As I deleted JFX SDK jars from my project lib folder, I readded them. Gradle adds every jar in lib folder with:
implementation fileTree(dir: 'lib', include: '**/*.jar')
Also, do not install JavaFX directly into JDK folder. It'll be impossible to update either without keeping unnecessary files, you'll never be able to find all JFX files to remove in case you want yo remove it, JFX src.zip replaces JDK src.zip in lib folder. They're meant to be separate.
Related
On Windows package org.eclipse.swt.win32.win32.x86_64 is used, while for Linux build it's org.eclipse.swt.gtk.linux.x86_64.
If nothing is specified in module-info.java, error message is java: package org.eclipse.swt does not exist
If in module-info.java both are specified:
requires org.eclipse.swt.gtk.linux.x86_64;
requires org.eclipse.swt.win32.win32.x86_64;
error message: module ... reads package org.eclipse.swt from both org.eclipse.swt.gtk.linux.x86_64 and org.eclipse.swt.win32.win32.x86_64
If only one requires is specified, then project works only on one platform.
What would be correct setup for module-info.java, so that project would run on both platforms?
It's a bug 559162 in SWT. Their Automatic-Module-Name in the SWT jar files manifest is impractical.
I suggest to stick to module-less builds (without module-info.java) until this gets fixed.
I am trying to setup VSCode to work on Java projects, but I'm running into some issues.
I currently use Eclipse (the "ide for rcp and rap developers" version/package).
In many of my projects, I have runtime dependencies and during development I specify a "Plug-In Dependencies" folder that points to the directory where these runtime jar files are.
This allows my code to compile and also my project does not have to contain all those referenced jar files when I export and create a jar because they will be available at runtime.
I have setup VSCode with the Extension Pack for Java, but it doesn't seem to recognize the plugin dependencies and all those imports are unable to be resolved.
Is there a way I can add these dependencies?
I'm using OpenJDK 11, IntelijIDEA 2019.2 and javafx-sdk-11.0.2.
When I wrote JavaFX project, I tried to add external runnable jar from maven project, but IntelijIDEA didn't see classes for this jar.
What I've done:
I added as external library own jar.
In the project tree I found it:
But I couldn't create class objects and use methods that contains this jar:
Why it happens?
If it's modular project
The reason was the use of the file module-info.java. As we know, JavaFX 11 is not part of the JDK anymore. So, we need to add this special file at the root of our packages w/ lines like:
module modulename {
requires javafx.fxml;
requires javafx.controls;
opens package;
}
From this moment, most likely you won't find classes until you add separately your jar in this code like:
requires name_of_jar;
Only after adding this, you can use your classes/methods from external libs.
If it's non-modular project
As mentioned by mipa, you can follow these instructions as alternative way.
Related links:
https://www.baeldung.com/java-9-modularity
https://medium.com/criciumadev/its-time-migrating-to-java-11-5eb3868354f9
How to use 3rd party library in Java9 module?
https://www.oracle.com/corporate/features/understanding-java-9-modules.html
IntelliJ can't recognize JavaFX 11 with OpenJDK 11
I'm building an Android app that has a dependency on a custom library, and Gradle is only willing to include my custom library when I use a project dependency, not when I use a files dependency to include the library's jar file. I'm building both my app and the library with the API levee 19 SDK.
failing dependencies section from build.gradle:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('libs/MyLibrary.jar')
}
If I use the above dependencies section, none of the class in MyLibrary.jar are included in the build apk file, as verified by extracting its classes.dex and running dexdump. I have also verified that all of the classes are present in the jar file I'm using.
If I use the following dependencies section, then all of the classes in MyLibrary are included in the apk file:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile project(':MyLibrary')
}
I'm using Android Studio 0.4.0, Gradle 1.9, and I think the Gradle plugin 0.7.1.
What is going on here? I'd really like to build my app with the API level 18 sdk to test compatibility, but I can't get that working unless I'm able to just use the jar file for my library.
Okay, this was my fault. My library's build.gradle was configured to only include the source files in the jar output file. The following is incorrect Gradle code and will give you the same problems as I've had.
task jar(type: Jar) {
from android.sourceSets.main.java
}
This answer shows how to fix the jar file creation. It's ugly, but it seems to work.
Jar task does not include dependencies in the final jar artifact.
From Gradle documentation on jar task:
The jar task creates a JAR file containing the class files and
resources of the project.
It assumes that since you are building jar for your project, all dependencies will be provided during runtime. As opposed to war, where all dependencies are usually included in the final artifact.
If you need to create "fat jar", which will include the dependencies, then look into specific plugins, for example gradle-fatjar-plugin.
It's a little bit of a longshot, but if you're not using Android Studio 0.4.0 and you've just added the jar file, try cleaning your project and rebuilding from scratch. We've seen this bug: https://code.google.com/p/android/issues/detail?id=63366 where libraries don't get included without cleaning the project, though this bug refers to a dependency downloaded from Maven and not a local jar file (which may or may not be an important difference). This was fixed in Android Studio 0.4.0 (more specifically, in the Gradle plugin 0.7.0).
I use eclipse for Google Android development.
I've created a library project ([x] Is Library in the Android-settings), which includes an external jar-file (Referenced Libraries). This library project are referenced in another Project (the actual project which will use the library project). This is done by add the project under the Android-settings.
the source compiles but if I want to execute it on the device, I get the NoClassDefFoundError for a class which is inside the jar-file which is included in the library project.
Edit: The jar-file ist added to the exported entries ([x] my.jar on the Order and Export-Tab from the library project)
Is there a clean way to get this working?
It has been clearly stated in offcial API here:
A library project can include a JAR library
You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file
The jar lib must be manually added to the dependent application project's build path, not only the library project build path itself.
Update from SDK r17:
This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:
Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)
For those who followed the steps(even check the projects in "Order and Export") and still have the java.lang.ClassNotFoundException in the API 17, the final step is to check that your compiler does not run with Java 1.7. If is 1.7 then you should change it to 1.6 for all your projects. After that it will ask to rebuild all the projects and successfully ran on my phone :)
To change the java compile version in eclipse, this is located in: Project properties > Java Compiler > Compiler Compliance level: 1.6
Go to project properties -> build path-> libraies
If you see your jar files like this
snmp4j.jar - e:\software\jars
Its may your problem
Add libs folder in your project and copy jar file in that folder. Right click jar file and go build path -> add to build path. Then you can see your jar as
snmp4j.jar - project_name/libs
Its worked for me.
I had two projects using the same library: one working, the other one crashing with java.lang.NoClassDefFoundError.
After nothing else helped me, I looked into the file project.properties in the root directory of my project.
The working project had the android.library.reference line (the last line below), the crashing one did not:
# Project target.
target=android-17
android.library.reference.1=../my-library-project
I manually added the line and it started working!
(Yes, I did try both (project) properties -- java build path -- projects and (project) properties -- java build path -- order and exports -- nothing helped.)
PS By the way, "project properties" has also the "project references" tab. No idea if it would work.
I had a minor issue when I upgraded to ADT17 where my libs weren't being imported properly. Turns out this is because my librarys were being linked as dependancies from my lib folder not libs!
Seems librarys have to be in the libs folder from now
I had a similar problem and non of the solutions out here fixed it.
Short version: the JAR was compiled in Java 1.7 and could not be found by Dalvik.
We build an internal JAR that we share across backend and mobile clients with Maven. The problem ended up being that the JAR was compiled with Java 1.7. Androids dalvik only supports Java 1.5 and 1.6. This is why everything works fine in Eclipse as it's not compiled to dalvik at this point.
We even specified the target and source version in the Maven compiler plugin to compile with Java 1.6. This did not work because only JDK 1.7 was installed on the build machine. A small note at the bottom of the Maven page gave us the hint: Note: Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version.
To see if you have this problem as well, rename your *.jar file to *.zip unpack it, and look in the MANIFEST.MF file for the Build-Jdk: parameter to see what Java version actually compiled your JAR.
Another thing to pay attention to is library package names.
If you are using ADT21 and you happen to have libraries that have the same package name, there will be error during compile but it will still compile and run in Eclipse, giving you an APK that is missing some of the resource classes. Hence the crash when you run the app.
If you compile it with ANT then you can see the compile error that says two or more libraries use the same package name.
To fix this, rename your library project by using Android Tools -> Rename Application Package. Then everything will go back to normal.
It took me almost entire day to figure this out...