Gradle Error while installing RichTextFX with Java 8 - java

I'm trying to use RichTextFX but when I do try to use it I get a long error (see below). I'm using IntelliJ IDEA 2018.3.4, JDK 8 and Gradle version 4.8.1. My current way of trying to install it is I downloaded the jar (richtextfx-0.9.2.jar) and move it into a folder in the project. I then add the jar as a library and save. Then I go to my JavaFX file, and make a new Code AreaCodeArea c = new CodeArea(); This will result in a large error. I think there is an error with gradle installing. I haven't used it before so I'm very new at it.
I am able to use the actual files (when not compiled into a JAR) to run the demos provided. This is in a different project, and the gradle libraries are added as external libraries when the project was created. The project I'm working on however does not have these extra external libraries.
Any support on what to do would be greatly appreciated. Thanks!
There Exceptions are:
java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: Exception in Application start method
java.lang.NoClassDefFoundError: org/fxmisc/flowless/Virtualized
java.lang.ClassNotFoundException: org.fxmisc.flowless.Virtualized
Test java code
package demo.javafx;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import org.fxmisc.richtext.CodeArea;
public class TestRichTextFX extends Application {
#Override
public void start(Stage primaryStage) {
Pane root = new Pane();
Scene scene = new Scene(root);
CodeArea c = new CodeArea();
primaryStage.setAlwaysOnTop(true);
primaryStage.setTitle("");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

You can't just download the JAR for RichTextFX and add it to your project. RichTextFX itself has dependencies that only downloading the JAR won't provide. In your case, you're seeing an error saying the Flowless dependency is missing. However, you don't have to download the JAR files yourself—that's what Gradle is for. You just need to add the dependency to your build script; the README of RichTextFX provides an example1.
repositories {
mavenCentral()
}
dependencies {
implementation 'org.fxmisc.richtext:richtextfx:0.9.2'
}
Gradle will pull in all the needed dependencies for you. For more information, see Introduction to Dependency Management.
Note that doing it this way you shouldn't have to declare a library in IntelliJ. If your project is setup as a Gradle project then IntelliJ will see the dependencies declared in your build script(s) and add them to the project. You may have to "import changes" after modifying the build script. These help pages provide more information.
1. The example uses compile but Gradle recommends implementation—at least for the more recent versions (compile is deprecated). Note that Android projects may still use compile, though I'm not sure.

Related

gradle build failing with exception failed for task ':compileJava'. byteBuddy library issue

Hello and thank you ahead of time for any help.
Firstly, I do know that other people have had this issue before and I've tried the solutions in all of their discussions and none of them have worked for me.
Basically, I'm trying to setup "gradle build" in the project folder for a java eclipse project so that I can begin to code an agent. I'm receiving an issue with getting the program to recogninse byteBuddy which is already in my lib folder and added to my dependencies in my gradle file.
This is my first time working with both gradle and byteBuddy.
When i try to gradle build in the project folder its says this:
Excecution failed for task ':compileJava'.
When i use --info, it provided me more details by saying:
All input files are out-of-date for incremental task ':compileJava'. Full recompilation is required because no incremental change information is available.
It proceeds to say:
....path.... java\main.java:4: error: package net.bytebuddy.agent does not exist
import net.bytebuddy.agent.ByteBuddyAgent;
I have done a bunch of research into the problem and I've seen things that it could be like java version mismatches with gradle, incorrect JAVA_HOME settings, and why the program doesn't pick up the jars that are clearly in my library.
I don't know if my issue is related to the above mentioned, but I haven't yet found other potential issues relating to my problem.
I am using:
Java eclipse,
java 1.8.0_212 (my JAVA_HOME is set to this),
gradle-5.4.1,
byteBuddy 1.2.12 library,
asm-7.1 library (which is said to be needed to run byteBuddy), and
jackcess 2.1.11 library (which i'm not sure is related to the issue but it came up in the gradle build before i tried bytebuddy with the same issue)
EDIT: I am running Windows 7 Professional
Here is my main file that was mentioned in the error message above. In the above code, I'm trying to get the commented out area to work, but eclipse isn't recognizing the ByteBuddy import:
import javax.swing.JFrame;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.matcher.ElementMatchers;
public class main
{
public static void main(String[] args)
{
mainFrame newBegining = new mainFrame();
newBegining.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newBegining.setLocationRelativeTo(null);
newBegining.setVisible(true);
}
/*Class<?> dynamicType = new ByteBuddy()
.subclass(Object.class)
.method(ElementMatchers.named("toString"))
.intercept(FixedValue.value("Hello World!"))
.make()
.load(getClass().getClassLoader())
.getLoaded();
assertThat(dynamicType.newInstance().toString(), is("Hello World!"));*/
}
Here are relevant snippets from my gradle file below(I believe they could be based on that I edited them in attempts to fix the issue and they were mentioned in other potential resolutions):
repositories {
jcenter()
flatDir { dirs 'lib' }
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'joda-time:joda-time:2.1'
compile 'net.bytebuddy:byte-buddy:1.9.12'
testCompile 'junit:junit:4.12'
}
compileJava {
options.debug = true
}
jar {
manifest {
attributes(
'Main-Class': 'main',
'Premain-Class': 'searchAgent.searchAgent',
'Agent-Class': 'searchAgent.searchAgent',
'Can-Redefine-Classes': 'true',
'Can-Retransform-Classes': 'true',
)
from configurations.runtime.collect { zipTree(it) }
}
As far as i understand, I think the issue relates to gradle's ability to recognize my byteBuddy library, but I'm not entirely sure.
I feel like the answer is something small, but i haven't been able to pin it.

How to fix Kotlin libraries not resolving in IntelliJ in Kotlin code (in a java project)?

I have two projects. One written fully in Kotlin that exports a Client artifact. I am trying to use the client in a second project that has a mix of java/kotlin code.
In the java classes I have no problem importing the kotlin files for use, but in any kotlin files, IntelliJ cannot resolve the imports. All the other kotlin code works fine and I can compile on the command line via maven with no problems. It's just an issue with IntelliJ not recognizing the package I'm looking for.
I see the package in both my maven toolbar as well as in the external libraries listed in the project. I've inspected the jars and sure enough the file I expect com/foo/bar/BazClient.class is present, but
import com.foo.bar.BazClient tells me the package bar (the code from the other project) does not exist. The very same import statement works just fine in java code.
Further adding to my problems the exact same java class that imports this client, if I convert to kotlin using IJ's builtin method, fails to compile in IntelliJ. The "build project" action completes successfully with no warnings/errors.
Kotlin client is defined as:
package com.foo.bar
import retrofit2.http.GET
interface BazClient {
#GET("/v1/fuzz")
fun getFuzz(): Call<FuzzResponse>
}
Working java code:
package com.whodat.wat;
import javax.inject.Singleton;
import com.foo.bar.BazClient;
#Singleton
public class CallTheService {
private final BazClient bazClient;
public CallTheService(BazClient bazClient) {
this.bazClient = bazClient;
}
public FuzzResponse callIt() throws IOException {
return bazClient.getFuzz().execute().body();
}
}
Failing kotlin code:
package com.whodat.wat
import javax.inject.Singleton
import com.foo.bar.BazClient // "bar" is red in editor
#Singleton
// Can't resolve "BazClient" here
class CallTheService(private val bazClient: BazClient) {
fun callIt(): FuzzResponse {
return bazClient.getFuzz().execute().body()!!
}
}
It turns out this was a problem in publishing the client artifact. We were using the maven shade and jar plugins to create the jars and was leading to many kotlin_modules in the jar which were confusing IJ
META-INF/client.kotlin_module
META-INF/descriptors.jvm.kotlin_module
META-INF/descriptors.kotlin_module
META-INF/descriptors.runtime.kotlin_module
META-INF/deserialization.kotlin_module
META-INF/kotlin-reflect-api.kotlin_module
META-INF/metadata.jvm.kotlin_module
META-INF/metadata.kotlin_module
META-INF/util.runtime.kotlin_module
META-INF/kotlin-stdlib.kotlin_module
META-INF/kotlin-stdlib_coroutinesExperimental.kotlin_module
META-INF/kotlin-stdlib-common.kotlin_module
META-INF/kotlin-stdlib-common-coroutines.kotlin_module
META-INF/kotlin-stdlib-jdk8.kotlin_module
META-INF/kotlin-stdlib-jdk7.kotlin_module
Removing those from the client build seems to have cleared things up, and now we just have the one client.kotlin_module.
This problem has a ticket in Jetbrains issue tracker. The ticket has not been resolved yet, but support said:
This is a known problem since the 1.2.50 release of the Kotlin plugin:
KT-25709. As a workaround, please stop bundling the Kotlin
runtime in the dependency jar (i.e. everything under the package
kotlin should be removed from the jar)

Eclipse gradle project setup fake error notification

I want to build a REST Service with Java Spring and followed this guide successfully.
After creating a new gradle project i copied the build.gradle file and started everything with gradle buildRun. It is all woring well, except that Eclipse underlines imports, variable declararations, standard
datatypes as unresolveable.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
For example are in this class String, SpringApplication, SpringBootApplication, Application and org.springframework marked as unresolvable. However Exlipse resolves them just fine. I hope someone can
tell me what i have to change, error detection is quite hard right now (:
The platform is:
Eclipse IDE for Java Developers
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200
OS: Linux, v.4.16.13-2-ARCH, x86_64 / gtk 3.22.30, WebKit 2.20.3
I had this issue before with Spring (although it was with with Maven) and I was able to resolve it by updating my Maven project and running a clean build. Check and see if it possible to "refresh" your gradle build/update dependencies:(For me it was Right-click -> Maven -> Update Project), and also try running gradle clean first, then build it to see if leftover artifacts are causing the issue.
If you get a "Could not find or load main class" or an error like that from Spring later, make sure your directory structure (from the project) is src/main/java/hello, with hello being the package containing your class files.

MarkLogic using JavaAPI

I have been trying a normal Java API using the same example as mentioned in this page. I had to download various JARs:
java-client-api-3.0.7.jar
slf4j-api-1.7.25.jar
com.fasterxml.jackson.databind.jar
jackson-core-2.2.0-rc1.jar
apache-httpcomponents-httpclient.jar
javax.ws.rs.jar
It still gives me NoClassDefFoundError on
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/params/HttpParams at com.marklogic.client.DatabaseClientFactory.newClientImpl(DatabaseClientFactory.java:322)
My Code:
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.document.*;
import com.marklogic.client.io.*;
public class JavaML {
public static void main(String args[]) {
System.out.println("Here");
DatabaseClient client =
DatabaseClientFactory.newClient(
"localhost", 8000,"admin", "######",
DatabaseClientFactory.Authentication.DIGEST);
JSONDocumentManager docMgr = client.newJSONDocumentManager();
docMgr.write("/afternoon-drink",
new StringHandle("{name: \"Iced Mocha\", size: \"Grandé\", tasty: true}"));
String doc = docMgr.read("/afternoon-drink", new StringHandle()).get();
//System.out.println(doc);
}
}
Run:
javac -cp .;%CLASSES% JavaML.java
java -cp .;%CLASSES% JavaML
%CLASSES% - path to all the jars mentioned above.
Please help - am I missing something? Or is it a mandate that I have to download all these JARs?
It appears from the error message that you are missing the httpcore-4.1.jar.
However, there are a number of other dependencies that you are likely to be missing as well.
If you are maintaining your own set of dependencies and building your classpath manually, then you should download the Java API zip, which includes all of the necessary dependencies in the /lib directory.
However, it would be much easier if you were to use a build/dependency management tool, such as Gradle or Maven. If you have the Java API as a dependency, it will download all of it's dependencies and will compile your application with the necessary libraries on your classpath. It makes upgrades much easier, facilitates automation, and is a best practice in favor of manually collecting and organizing dependencies.

Gradle dependency vs. java import statement in Android studio

I'm trying to pull together an Android project, it includes several library packages, and a demo app that utilize the libraries.
I'm using Android Studio and Gradle. (I used to work with Eclipse, without gradle.)
So here in Android Studio, I have a project including several packages(or modules? what's the difference in concept?)
I have a core library project. And another library, say Flavor, that utilizes core.
In the Flavor module,
In build.gradle file, I have
dependencies {
....
compile project(':**core-project**')
....
}
I understand it as that Gradle add the core project build path to my Flavor project. (Same way that you can do it manually in Eclipse. See picture)
In java file,
import org.project.**core**; //this shows Unused
public MyFlavorClass extends CoreClass {
...
}
I deleted the import statement and it seems fine.
So why the import statement is not needed here?

Categories

Resources