Adding jars with IntelliJ IDEA 12 - jar

I am trying to follow the description here Correct way to add lib/*.jar to an IntelliJ IDEA project? in order to make some static utilities from a jar available, but keep getting "Cannot resolve symbol" errors.
I do the following: Go to project structure with Ctrl+Shift+Alt+S -> select module -> Dependencies ->
add -> Library -> find the jar -> accept the class and source destinations.
In the linked description "Project Libraries" is chosen instead of "Library", but I don't see that option running version 12.1.4.
In the project view, I do have a library under "External Libraries" containing the jar afterwards, but I keep getting "Cannot resolve Symbol" when I use a static method from the jar. When I expand the jar from the project view under its library under External Libraries, the needed class is present.I have tried different things from the Project Settings eg. adding the jar as "Jars or directories" but with the same result. The code I am referencing the class in the jar from, has an explicit package statement.

After adding the jar,Clear the Cache first and then run the sbt Clean,Reload and Update commands respectively from the command prompt or sbt console,which will helps the ide to adopt the code from the jar.

Related

java.lang.module.FindException: Module test not foundIntellidea

I am have this Exception please help me!
"Error occurred during initialization of boot layer
java.lang.module.Find Exception: Module test not found"
But i write VM option "--module-path "D:\UT java\javafx-sdk-17.0.1\lib" --add-modules javafx.controls,javafx.fxml"
and i have module-info.java "
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
requires java.sql;
requires java.desktop;
requires jdk.jfr;"
i add my sdk. And if i create javafx demo project and execute him it work. and if i start change fxml file and change controller i have this exception.
I have IntellIJIdea 2021, javafx-sdk-17.0.1, jdbc jr 8,11,16
Steps to fix:
Delete the JavaFX sdk (you don’t need it).
Delete old Java versions (they are obsolete).
Update your IntelliJ IDE and IDE plugins to the most recent release, 2021.3.2+.
Create a new JavaFX project using JDK and JavaFX 17.0.2+.
Select Maven for the build system unless you know and prefer Gradle.
Do not set VM arguments, you don’t need them.
Adding modules via the --add-modules VM arguments is unnecessary when you have a valid module-info.java file.
The --module-path is still required so that the modules can be found, but Idea will provide the correct path for your modules automatically when it recognizes the modules through your Maven dependencies.
So you don't need to explicitly define the --module-path VM argument yourself for a Maven based build (that would be difficult to do anyway because the modules are all downloaded to different directories in your local maven repository).
Test it works following the Idea create new JavaFX project execution instructions.
Add additional modules one at a time by adding their maven dependency to pom.xml and the requires clause to module-info.java.
Ensure you synchronize the Maven and Idea projects between each
addition.
See, for example, this question on correctly adding the javafx.media module.
Adding other modules such as javafx.web, javafx.fxml or javafx.swing follows a similar pattern.
Test between each addition by building and running the project, to ensure you haven’t broken anything.
Copy your original source code into the appropriate package directories under the new project source directory:
src/main/java
Place resources in:
src/main/resources
following the Eden resource location guide.
Fix any errors, ensure everything compiles and runs, then test it.

Error: JavaFX runtime components are missing, (Permanent Solution)

I know you can solve this by adding
--module-path "pathToLib" --add-modules javafx.controls,javafx.fxml,javafx.graphics when running the jar file in command line.
But my question is, Is there no permanent solution to solve this error in system settings or configurations and be able to run a jar file as normal as java -jar myfile.jar rather than every time I am suppose to add the module java --module-path "C:\Users\..\Downloads\javafx-sdk-17.0.2\lib" --add-modules javafx.controls,javafx.fxml,javafx.graphics -jar myfile.jar
Also I know you can make a script for this operation for every jar file, but I was thinking of something like system settings or configuration that will be applicable for all jar file with javafx, and be able to run the jar file as normal as java -jar myFile.jar
I am using Ant as a build tool.
Recommended Alternatives
See the packaging resources of the JavaFX tag for recommended alternate solutions to a jar distribution: jlink, jpackage, or native image.
Using JRE's that include JavaFX
Pre-installed JREs that include JavaFX, such as some Bellsoft, Zulu, and Corretto distributions, will execute JavaFX apps without additional module specifiers because they include the JavaFX modules in the base module setup for their distributions.
Note, you must use the correct versions of the JDKs if you want a JDK which includes JavaFX (not all JDKs include JavaFX):
for BellSoft, download and install the "Full JDK", not the "Standard JDK".
for Zulu, download and install the package type "JDK FX", not "JDK".
You can also create your own JRE distribution that includes JavaFX modules using jlink (which is actually simpler to do than it may sound).
Using ant to build a single JAR containing App and JavaFX components
But I still hope that there might be a solution for the above while working with ANT as building tool for JavaFX.
There is some info on building modular JavaFX apps with ant in this answer:
bad name in value for --add-modules when trying to compile through ant
It probably isn’t everything you are looking for though.
To create a single executable jar using ant, you could try emulating the output of this maven JavaFX shade on classpath answer:
Maven Shade JavaFX runtime components are missing
But use ant tasks to build the massive shaded jar instead of maven. I don’t have explicit instructions for that, you would need to work out to accomplish that non-trivial task yourself.
The created jar will include a launcher class, your application code, dependent library code, JavaFX java, and native code. The jar will run on any modern JRE as long as you have included the native code for the relevant platform. The jar will run in the unsupported classpath configuration.
Zip Distributions
Or (better) create a zip distribution:
only put your own code in your app jar.
place the dependent libraries and JavaFX modules in a lib directory.
Create a script that invokes Java with your jar file running with the modules in the lib directory added.
Make your app modular if possible:
Define a module-info.java.
This step isn’t strictly necessary or reasonably possible for some apps.
Use ant to place everything in a zip file for distribution.
Include a jlink generated JRE in the zip if you want.
Note: the maven JavaFX plugin, once properly configured, can accomplish most of these tasks with a single command:
mvn javafx:jlink
Additional info
See the eden guide for resolving JavaFX runtime components.
Add a module-info.java file under your java/ folder and populate it with the following content:
module module_name {
requires javafx.controls;
requires javafx.fxml;
requires javafx.graphics;
requires java.base;
requires java.desktop;
opens com.example.matformater to javafx.graphics;
opens com.example.matformater.controller to javafx.fxml;}

Link Realm within a dynamic library ends in "ld: framework not found Realm for architecture i386"

I've created a custom dynamic library (let's call in LogLibrary.framework) in Swift 2.1. No I'd like to link the Realm.framework and RealmSwift.framework with it.
I did follow the installation instructions provided on https://realm.io/docs/swift/latest/.
These steps are:
Link Binary with Libraries (Realm.framework and RealmSwift.framework added)
Build Phase -> Add copy files Phase -> Destination "Frameworks"
Run Script Phase -> bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"
Unfortionally, if l link the LogLibrary.framework in my sample Application, I always get the following compile error:
ld: framework not found Realm for architecture i386
I did not set any additional linker flags in the sample Application.
However, It works if I also link the Realm.framework and RealmSwift.framework in the sample Application - but that's not what I want, because they are already linked within the LogLibrary.framework
Any Ideas how I can get rid of the compile error?
Sample Project: https://github.com/sehdich/RealmLinkError.git
You should link Realm and RealmSwift.framework to PhotoApp target too. Because those frameworks are not static libraries. They are linked dynamically. So they are still specified to link app's target and included in app bundle.

Add JavaFX (of JDK8) in sbt (using the play framework)

The goal is to have a standalone Play Framework (2.2) application having an additional status window open containing some javafx (javafx-8) elements.
Since JavaFX classes are now on the default runtime classpath for an Oracle Java 8 implementation using javafx.* in my classes and compiling with sbt should just be fine.
However sbt can't find these classes and quits with
play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: javafx/application/Application]
when executing
..\path-to-play-framework-2.2\play project run
The best way to fix this problem seems to be the modification of build.sbt in the project directory. What can I do to add the missing (class) path?
Sadly JavaFX doesn't link that easily to an sbt build. You need to set your JAVA_HOME environment variable and do modifications to your build file.
Here I have a repository where this is set up. The important bit if you are using an sbt build rather than a scala build is this one:
unmanagedJars in Compile += Attributed.blank(
file(System.getenv("JAVA_HOME") + "/jre/lib/jfxrt.jar")),
fork in run := true
The reason for this is that jfxrt.jar is the archive containing the JavaFX runtime and it is not included in the classpath of an sbt project by default.
Anotherway is to set the Classpath for sbt. This can be done on the machines which can't resolve JavaFX.
SBT_OPTS="-Xbootclasspath/p:/usr/share/java/openjfx/jre/lib/ext/jfxrt.jar"

PLCrashReporter in XCode 4 - won't compile in Simulator

I must be doing something totally stupid here, but I can't get the PLCrashReporter framework included in my project. Here are the steps I took to get the framework:
Downloaded the .dmg file from the official project site on google code
Copied the CrashReporter.framework folder to the root directory of my project
Added the framework by going to my project, selecting the target, going to the Build Phases tab, opening the Link Binary With Libraries section, clicking the plus sign, and adding the CrashReporter.framework folder
I am pulling in the framework in my class file by using
#import <CrashReporter/CrashReporter.h>
When I try to compile under 4.3 simulator, I get the following errors:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_PLCrashReporter", referenced from:
objc-class-ref in AppDelegate+CrashReporting.o
"_OBJC_CLASS_$_PLCrashReport", referenced from:
objc-class-ref in AppDelegate+CrashReporting.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I compile under the device, everything is fine. Is there some sort of header or library search path I need to include?
The app compiles under XCode 3 without issues under all configurations.
I had the same issue and was able to resolve it. Here are the steps I completed...
Download the PLCrashReporter source release and unzip.
Open the PLCrashReporter xcode project. This project is setup to use an old SDK, update all the required SDKs for each target to get rid of the warnings. This is also required to compile in the next step.
Navigate to the CrashReporter-iPhoneSimulator Target. Under the Build Settings: a) set "Perform Single-Object Prelink" to "No", b) set "Mach-O Type" to "Static Library".
Select CrashReport-iPhoneSimulator : [IOS simulation (ie iPhone 4.3 Simulator)] and click build.
Navigate to your build directory for the PLCrashReporter. For me, it was /Users/username/Library/Developer/Xcode/DerivedData/CrashReporter-(random characters)/Build/Products/Debug-iphonesimulator
Copy the libCrashReporter-iphonesimulator.a from the build directory in step 5 to the iphone application project directory you want to add the crash reporter to.
Open the your iphone application project in xcode.
Download the PLCrashReporter binary release and extract the framework to a local directory.
Add the CrashReporter framework to your project using this SO post.
Following the same procedure as step 9, add the libCrashReporter-iphonesimulator.a static library to the "Link Binary with Libraries" section of the build phases. No *.framework directory is needed when adding a static library.
Review the "Link Binary with Libraries" in the Target. Make sure the libCrashReporter-iphonesimulator.a is listed above the CrashReporter framework. You can drag and drop to reorder.
I hope this helps.
For anyone else looking for this information:
I followed the same steps given above however I was getting errors. I deleted the static library and only included the framework (which you can get from their dmg).
It worked perfectly for me. I think the process of creating static library by building the project was old (before they created a framework).
Thanks.
Don't forget to include
libstdc++.dylib
in "Link Binary With Libraries".

Resources