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.
Related
I have this gradle java project with this setting.gradle
pluginManagement {
repositories {
maven {
url "${settings.ext.get("artifactory.contextUrl")}/example"
credentials {
username = 'myemail'
password = 'mypassword'
}
}
}
When i import it into IDEA, everything works fine, but i want to import this project into VS Code, but when i try it, gradle build passed just like in IDEA, but it still shows many errors:
error
and java dont see imports imports
obviously it shouldn't be problem with project and config, but with vs code, cause like i said, IDEA import it normally, does any have idea?
I tried turn on nested projects in vs code gradle, but without change, really don't know where could be difference between IDEA and VSCODE gradle.
Install the Gradle for Java extension. Check to see if all dependencies are included.
For more information on using gradle in vscode see here.
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.
I had a maven project with old docx4j dependencies, and I wanted to update to java 9. During the update I changed my project from maven to gradle.
So now I have a gradle project in IntelliJ with this dependencies:
dependencies {
implementation('commons-io:commons-io:2.6')
implementation('javax.xml.bind:jaxb-api:2.4.0-b180725.047')
implementation('org.docx4j:docx4j:6.0.1')
implementation('org.docx4j:docx4j-ImportXHTML:6.0.1')
implementation('org.docx4j:docx4j-export-fo:6.0.1')
testImplementation('junit:junit:4.12')
}
The build is working, but if I want to open a .docx file, with Docx4J.load(...) or WordprocessingMLPackage.load(...) it throws a RuntimeException.
In debug mode I can see this message: Class not loaded : org.docx4j.jaxb.Context
This Context.java file has a static code block like this:
static {
...
}
I think it's gradle specific error, because I created a new maven project with the same code and dependencies as the gradle project, and it works.
Is there any solution for this, or should I use maven in the future too?
There is a Gradle-specific answer at https://stackoverflow.com/a/51235096/1031689
Or to "add module" instead, see for example:
https://www.concretepage.com/questions/531
https://github.com/IntershopCommunicationsAG/jaxb-gradle-plugin/issues/11
Or mac java 9 gradle ClassNotFoundException: javax.xml.bind.JAXBElement when building
I'm trying to learn Spring framework so I decided to follow tutorials available on Spring.io website. I have an issue in my application with the chapter: http://spring.io/guides/gs/rest-service/
I did it with friend day before and app worked and is still working. I tried to do it on my own and in main class I receive error:
Error Stack Trace
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files
The method run(Object, String...) from the type SpringApplication refers to the missing type ConfigurableApplicationContext
I'm trying to do it at my company office right now, can security software in my company's broadband be at fault?
Main class: Application.java
package hello;
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);
}
}
I think this is related to your class path, which do not have required class files. I suggest you to build project stand alone without any ide to check all dependencies resolution and make sure works fine. For that simply set JAVA_HOME and MAVEN_HOME (assuming you are using build tool is MAVEN)on the environment variable and build your project without any ide (Netbeans or Eclipse) with command (mvn clean compile package install) and it will resolve all your dependencies related problem and download required jars from central repository and on successful build jar will be created in target directory of your project.
And if you are using any IDE then make sure all dependencies are available on the class path.
In your case required jar is spring-boot-starter-web to resolve issue of ConfigurableApplicationContext.
I have resolved my problem by simply right-clicking on my build.gradle file and going into gradle tab, then select refresh. It was fault of compiler, similar issue when people used to develop Android apps on that IDE. Sometimes you have to manually refresh it.
I've downloaded Junit version 4.10 and loaded the jar via the build path but I seem to get this error message when running a Junit test in Eclipse:
Error: Could not find or load main class org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
My Test class is the following:
import org.junit.*;
import static org.junit.Assert.assertEquals;
public class InternetConnectTest {
#Test
public void testConnectMethod(){
InternetConnect net = new InternetConnect("www.google.com");
assertEquals("Result", "www.google.com", net.url);
}
}
I came across this after I updated java versions: "junit: could not load main class 1.1". Go into the eclipse external tools configurations, open the entry for the ant file you are running, then go to the JRE tab, and select "Separate JRE", also making sure your new jre is correctly listed in the Installed JREs...for me, this took care of it.
This is an Eclipse error message. It seems your installation is corrupted. Try using a fresh installation of Eclipse.
Before trying a fresh install i just restarted eclipse and it did the trick.
I just had the same problem.
I relaunch Eclipse with the "-clean" option, and it did the trick too.
Edit:
How to run eclipse in clean mode? and what happens if we do so?