I'm working on a java project with Eclipse. My module-info.java contains the following lines of code :
module MyVelibGroup13 {
requires org.junit.jupiter.api;
requires junit;
}
and when generating javadoc with Eclipse (Project > Generate Javadoc) I get :
Loading source file C:\Users\Morgan\git\GroupProject13\MyVelibGroup13\src\module-info.java...
C:\Users\Morgan\git\GroupProject13\MyVelibGroup13\src\module-info.java:2: error: module not found: org.junit.jupiter.api
requires org.junit.jupiter.api;
^
C:\Users\Morgan\git\GroupProject13\MyVelibGroup13\src\module-info.java:3: error: module not found: junit
requires junit;
^
2 errors
My code runs withouh any problem, including JUnit tests.
Anyone knows how I can generate the javadoc without this error ?
EDIT :
I tried adding --add-module to the VM like this post but it didn't work. I've entered it like this :
Image of the window to generate javadoc:
You need to add JUnit to your BuildPath. Rightclick your project and select BuildPath and then Configure BuildPath. Now select Modulepath and then Add Library. There you can select JUnit.
Another way is to write a JUnit test. Eclipse shows you an error and will show you a quickfix where you coul add JUnit to your BuildPath.
Select BuildPath
Add JUnit
Related
I installed JUnit-Tools 1.1.0 in eclipse market. As per the documentation, they want the test-projects and the mock-projects to be created manually.
My class structure is like below :
I tried creating a test package like com.unifiedportal.core.unifiedportal.service.test and tried generating the test classes from the JUnit-Tools..
Got an warning like below :
Let me know how i should proceed with creating the test-project for this.
If you want to generate the tests under the same project you are in then remove Test-project-postfix in the junit tools preferences, otherwise let the postfix as it is and create a project (not a package) with the same name than your project plus that postfix.
Look an example of my config for generating the tests in the same project under src/test/java, because I don't want my tests to be in a separated project:
you can add the jars as maven or gradle dependencies.Change the test-source-folder-name to src/test/java and generate the test cases using the plugin.This will generate the test cases in your test folder
In my Jhipster generated file entityNameQueryService.java , eclipse indicates the following line as error, but project compiles successfully.
So, this must be the configuration issue with the eclipse ide. Couldn't figure it out myself..
if (criteria.getId() != null) {
specification = specification.and(buildSpecification(criteria.getId(), FRCommunications_.id));
}
The error message is
"FRCommunications_ cannot be resolved to a variable"
For your information, FRCommunications is my entity name.
Does anyone have a fix for this?
For eclipse, After
mvn clean install -nsu
just right click on target/generated-sources/annotation and select "Use as Source Folder"
JPA static metamodel which is used for JPA filtering in JHipster requires generating classes (named like the entity but suffixed with '_') at build time through an annotation processor, this is configured for maven and gradle so you can run a build and it will generate missing classes.
Alternatively, if you don't want to build using maven or gradle see https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html#_eclipse
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 have project xxxWeb using project xxxAPI. Both projects are sub project of a parent project. Project xxxAPI uses a third-party library jar jar1.jar, which has a class somepackage.ClassA. Project xxxAPI itself also has identical somepackage.ClassA that project xxxWeb intends to use.
However, Eclipse load somepackage.ClassA from jar1.jar instead, resulting in compilation error because jar1/somepackage/ClassA doesn't have the necessary fields like in xxxAPI/somepackage/ClassA.
In xxxWeb project classpath, Eclipse place xxxAPI project to the very end, which probably why the compiler pick jar1/somepackage/ClassA instead of xxxAPI/somepackage/ClassA.
This is not a problem in IntelliJ however.
Is there a cure for this?
The build script work fine, so I this is a question on Gradle's Eclipse plugin, and how to manipulate the generated classpath?
This is a bug of gradle as of version 2.14.1. A workaround is to utilize the hook given by Eclipse Gradle plugin to remove the duplicated classpath entries
eclipse {
classpath {
file {
whenMerged { cp ->
cp.entries = cp.entries.unique{a,b -> a.path <=> b.path}
}
}
}
}
I need to write a short test for some Java code. I used CTRL+SHIFT+T to generate one with IntelliJ, and selected "Groovy JUnit" as the testing library, then wrote the following test:
package util
class FibonacciHeapTest extends GroovyTestCase {
FibonacciHeap<Integer> heap
void setUp() {
super.setUp()
heap = new FibonacciHeap<>()
}
void testAddInOrder() {
testForItems 1..1000
}
private void testForItems(Range<Integer> items) {
items.each {heap << it}
assertEquals heap.size, items.to
items.each {assertEquals heap.remove(), it}
}
}
However, when I right click on the test case in the project window, I don't get the "Run All Tests" option that I normally do with JUnit tests, and the compiler throws the following error:
Information:2/4/15 8:15 PM - Compilation completed with 2 errors and 0 warnings in 2 sec
/home/patrick/IdeaProjects/hackerrank/src/test/java/util/FibonacciHeapTest.groovy
Error:(3, 1) Groovyc: unable to resolve class util.FibonacciHeap
Error:(9, 1) Groovyc: unable to resolve class GroovyTestCase
Trying to import GroovyTestCase or FibonacciHeap manually causes the same error. IntelliJ does not add any import statements when I let autocomplete finish the names for me, like it usually would with Java code.
What am I doing wrong?
This worked for me :
Open Gradle window (on right side in my case)
Click on refresh button
Done
I had a similar problem with creating test classes in IntelliJ, and it was solved when creating a new directory outside of the com.company folder (where I had the class I wanted to test).
Create a new directory for the test classes on the same level as your src folder
Right click on your new test directory, and "Mark directory as" --> "Test Resources Root"
Now create a test class, which should automatically be added to your test directory.
Build -> Rebuild project in the IDE itself (as opposed to maven, in my case) did it for me.
In my case, what I did to resolve the issue was rather simple.
Close IntelliJ
Open the attached homepage...
Remove your project by clicking on the x then...
Click on Import Project, Navigate to the build.graddle file of your project and open.
That was it and all the Red highlightings disappeared.
maybe you need add groovy-all rather then groovy,such as :
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
You have to configure Groovy SDK first. See the screenshot
More detailed description in the official document: Configuring Global, Project and Module SDKs
As #sman591 pointed out in a comment, if you are getting the error:
groovyc: unable to resolve class groovy.util.GroovyTestCase
and you already have groovy as a dependency then you are probably just missing the junit dependency.
In IntelliJ IDEA I re-imported the project. It worked then.
I closed idea. I removed .idea folder in the project. And I imported the project.
Then I needed to set up Groovy, see previous answers, mark test directory as test source in all modules of my project.
I was selecting the root folder which had build.gradle file in it, but it didn't work.
Steps followed are similar to #Pila
close the project from intellij
remove .idea, log, out folders
go to intellij dashboard
import project from existing resources
select build.gradle file <-- this is important
now you should see all the tasks are getting build in the background, and once build is finished all red lines are gone.