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.
Related
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 the Java library for the Google Maps API but cannot find the code at runtime. I've added the repository and dependencies to build.gradle as detailed in the readme. Everything compiles fine, the import statement autocompletes, I can open the source code in Eclipse through "View Declaration," and I can see Google Maps in the Java build path.
import com.google.maps.GeoApiContext;
// Throws exception!
GeoApiContext.Builder builder = new GeoApiContext.Builder();
Why is this library visible at compile time but not runtime?
ETA: The application is packaged as an EAR file and deployed to a web server.
With the scarse details you provided, my guess is that you built a jar file and then ran java -jar myApplication.jar.
The default jar file only contains the classes of you own application, and not its dependencies. If you want to make an executable jar, you have several options. Some of the more popular are:
Use the shadow plugin, which will repackage the jar to make it "fat" with all its dependencies.
Use the standard distribution plugin that will create a zip (or tar) of your project and its dependencies. It will also a script for setting the classpath correctly.
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.
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...
I have a project that shares models with my android project. I have a separate eclipse project just for models and other shared code. I add this to my play project as a dependency in eclipse.
In eclipse, play compiles and starts without problem. However, I went to deploy to GAE and found that the compilation stage of play's packaging fails because it can't find the models.
I suspect I could hack the ant build files, but that seems brittle.
Is there a standard way to add extra directories to the play compilation source tree or the classpath?
Make a jar-file with your classes and put it in /lib. That's where I put my libraries.
Files in the application /lib folder is automatically added to the class path by Play Framework. See Classpath settings
From Anatomy: "The app directory contains all executable artifacts: Java and Scala source code, templates and compiled assets’ sources" ... and further: "You can of course add your own packages, for example an app/utils package"
You can copy java source files to make a hierarchy of packages under /app, e.g.:
/app/sharedcode/project2/models/domain1 and import that in WhateverController.scala as:
import sharedcode.project2.models.domain1._