Building with Lombok's #Slf4j and Eclipse: Cannot find symbol log - eclipse

I have the lombok plugin in Eclipse and enabled annotation processing in Eclipse under java compiler, but still it is unable to recognize the log statements when I use #Slf4j annotation.
Do we have to make any other settings?

You also have to install Lombok into Eclipse.
See also this answer on how to do that or check if Lombok is installed correctly.
Full Disclosure: I am one of the Project Lombok developers.

I also faced the similar issue on log and #Slf4j on my STS environment. To resolve this, here is what I did on spring tool suite (sts-4.4.0.RELEASE) and lombok-1.18.10.jar (current latest version available in mavenrepository).
If having maven project, ensure lombok dependency added to it. Else you need manually add the jar to your project classpath.
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
Clean build the maven application. This will download lombok jar in your .m2 location by default from maven repository.
The path would be org\projectlombok\lombok\1.18.10\
Now open command prompt and navigate to the lombok path and execute command java -jar lombok-1.18.10.jar
C:\xxx\xxx\org\projectlombok\lombok\1.18.10>java -jar lombok-1.18.10.jar
Opens up lombok dialog box. If see message Can't find IDE
Click Specify location...
Provide the path to your STS root location
My case it is
C:\apps\sts-4.4.0.RELEASE\SpringToolSuite.exe
Install/Update
Install successful
Click Quit Installer
Now in explorer navigate to your STS root path.
C:\apps\sts-4.4.0.RELEASE\
We see lombok.jar placed in the sts root path
Now edit in notepad SpringToolSuite4.ini file
We see following appended at the end
-javaagent:C:\apps\sts-4.4.0.RELEASE\lombok.jar
Start STS using SpringToolSuite4.exe
Clean, rebuild your project.

So like others, i also faced this issue. Below is what I did.
Installed lombok.jar like explained here.
Tried restarting eclipse. (Did not work)
Tried refreshing gradle project. (Did not work)
tried what Hervian suggested in his answer here. (Did not work)
Closed the projects, deleted from workspace and then re-imported. Bam!! Worked.

I got the same error even after Lombok was installed. For me the solution was to add another lombok annotation (i used #Data) to my class after which the eclipse errors went away. Perhaps this force refreshed some cache.
Of course, I simply deleted the #Data annotation afterwards.

this got the fix to me by adding the slf4j dependency, Lombok can identify the slf4j but does not get the download, this is true for java project if you are using spring boot then slf4j comes by default.
here are my dependencies
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>

Related

How to use lombok in Eclipse/STS or Intellij Idea?

After lombok dependency add into pom.xml and update repository, it can't work well, IDE could not identify lombok's annotaiton. How could I do?
First step, you need to add lombok dependency in your pom.xml, and update maven dependencies to download lombok.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
And then, if you use Eclipse/STS as your IDE, you need to install lombok. Close your IDE first, and execute below command:
C:\Users\a243903\.m2\repository\org\projectlombok\lombok\1.16.20>java -jar lombo
k-1.16.20.jar
If you use Intellij Idea as your IDE, you need to install lombok plugin:
Go to File > Settings > Plugins.
Click on Browse repositories...
Search for Lombok Plugin.
Click on Install plugin. Settings -> Compiler -> Annotation
Processors, make sure check box Enable annotation processing
Restart IntelliJ IDEA.
Lombok plugin for IntelliJ is available here:
https://plugins.jetbrains.com/plugin/6317-lombok-plugin
Install it and restart IntelliJ.

MILO OPC-UA Download with Maven

I tried to use the milo opc-ua Implementation. At first I download the source with Eclipse/Maven to my local working directory.
File -> Import -> "Checkout Maven Projects"
The Download works fine for me. After this, I tried to update the project files.
Right-Click -> Update Maven Project
The "build-tools" work well for me, everything is done without any errors. But when I try this with the other "folders" (client-examples, ...) I get the following error:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (execution: validate, phase: validate).
The following code shows the pom-file of the client-examples:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<parent>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-examples</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>client-examples</artifactId>
<dependencies>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>sdk-client</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>server-examples</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
The pom.entries, shown in https://github.com/eclipse/milo, are in the file. I also checked this for the other sources. But whats going wrong?
I'm using eclipse-neon and maven2eclipse.
Thanks for helping,
Andreas
The errors says that the M2Eclipse plugin has no idea how to map the execution of checkstyle into some build step for the IDE. M2Eclipse tries to set up your local IDE project to replicate the behavior of the Maven build.
By default M2Eclipse is missing the support for the checkstyle Maven plugin. Therefore you get this error. There are two ways to handle this:
You can simply make Eclipse ignore those errors
You can install the checkstyle plugin for Eclipse and have checkstyle run the same way the maven build does it, getting all validation information right into your IDE.
In order to install checkstyle do the following:
Locate the location where the error is reported in Eclipse, issue the "Quick fix" command (normally Ctrl-1)
Select "Discover new m2e connectors":
Review the dialog and press "Finish":
Wait and let Eclipse restart
That should be it.

Why does addition of MigLayout still give an error inspite of adding the MigLayout jar file in the libraries in netbeans 8.0?

Though I have configured the classpath and added the jar file in the library of the project , it still gives me an error as "package net.miginfocom.swing. does not exist".
What can I do to avoid this error?
You can use maven to automatically download MigLayout. Just click new project, select and maven from categories, then Java Application. Once created go into the "pom.xml" (within Project Files) and paste this under the properties section:
<dependencies>
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>3.7.4</version>
</dependency>
</dependencies>
Then just build the project and maven will download and install MigLayout. Hope this helps.

Missing artifact "sun.jdk:jconsole:jar:jdk"

When adding Arquillian to a Maven build I get the above exception in Eclipse:
Missing artifact sun.jdk:jconsole:jar:jdk
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.1.7.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-persistence-dbunit</artifactId>
<version>1.0.0.Alpha7</version>
</dependency>
(The message is not the problem, but that Eclipse refuses to compile the project because of it. Maven works, though.)
Naturally the first thing I did was trying to exclude it from the Maven dependencies (wildfly-arquillian-container-managed is where the dependency tree states the dependency comes from):
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<exclusions>
<exclusion>
<artifactId>jconsole</artifactId>
<groupId>sun.jdk</groupId>
</exclusion>
</exclusions>
</dependency>
There was no change. I tried to start Eclipse with -vm C:\Program Files\Java\jdk1.8.0_60\bin. And tried to edit the JDK in "Preferences -> Installed JREs" to contain the JAR in the tools directory. But nothing works.
What can I do?
I put my dependencies like this and it works fine:
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-embedded</artifactId>
<version>8.1.0.CR1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.15</version>
<scope>test</scope>
</dependency>
<!-- Arquillian -->
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-embedded</artifactId>
<version>8.1.0.CR1</version>
<exclusions>
<exclusion>
<groupId>sun.jdk</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
See that the exclusion tag is in the "wildfly-embedded" dependency...
Don't forget to command "mvn install" and click right button at project and "Maven Update", if it doesn't work try delete folder "~/.m2/repository" and download all the dependencies again.
Alastair, thanks for solving the problem. The cause lies in the the pom of the transient dependency org.wildfly:wildfly-cli (8.2.0.Final). There you can find the following dependency declaration:
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>jconsole</artifactId>
<version>jdk</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/jconsole.jar</systemPath>
</dependency>
Actually, the jar is located in ${java.home}/lib/jconsole.jar.
P.S.: The version is also insufficient. So, I deleted this version from my local maven repository.
I faced this while working in a Windows machine. The project itself worked perfectly fine in my Ubuntu machine. However the project's build failed with exactly that message, induced by a transient org.wildfly:wildfly-ejb dependency.
Missing artifact sun.jdk:jconsole:jar:jdk
I didn't feel the project configuration needed to be changed as it's supposed to just work fine across all environments and thus the Windows environment itself must have been wrong. My first thought was that Eclipse itself is in some way using JRE instead of JDK.
So I checked java -version in CMD and it appears to point to a JRE installed somewhere in /Program Files folder while I've always been manually installing JDKs in /Java folder. Then I inspected the %PATH% environment variable in Windows settings. It appears to include a /ProgramData/Oracle/Java/javapath. That folder contained a few symlinks to the JRE in /Program Files folder. That was thus actually being used to start Eclipse and run all its tasks. When I removed it (there was already a JDK/bin further down in %PATH% setting) and restarted Eclipse and re-executed Maven build, the error went away.
No changes needed to pom.xml or Eclipse configuration. Just watch out with what's Windows all installing and updating for you in the background and check your %PATH% if it still has JDK in top.
The reason of the problem is that the jconsole.jar is part of the jdk, thus it is not distributed as an ordinary maven package.
Typically, project pom.xmls insert this jconsole.jar as a system package, i.e. it doesn't even try to download them from the central maven repo. Although it would be possible to distribute it also on this way.
The simplest solution of the problem is to use a jdk which contains this jconsole.jar.
Alternatively, you can download this jar from anywhere, only you have to make it reachable in the compilation classpath.
Or, you can also modify the pom.xml, or install the package manually into your local maven repo, as the other answers state.
I spent the best part of a day fighting this problem. Simple solution is to manually install the missing jar from your jdk using maven, something like:
c:\workspace\prism>mvn install:install-file -Dfile=C:\java\jdk\lib\jconsole.jar -DgroupId=sun.jdk -DartifactId=jconsole -Dversion=1.8 -Dpackaging=war.
Who knows why eclipse cannot do this ...
Maybe is more of a workaround than a proper solution, anyway I solved this issue by removing the profile "activebydefault" in the pom. This way, Eclipse won't complain for the "Missing artifact sun.jdk:jconsole:jar:jdk" but the JUnit test won't run in Eclipse - as I use testing only from maven test, and not the Eclipse embedded JUnit runner, it just need to specify which profile ID you want to run against.
I was facing the same issue, but none of this was a perfect solution for me. Steps to solve :
Check if you are pointing to the JDK location correctly :
echo $JAVA_HOME
Open pom.xml from IDE (mine is eclipse), select Dependency Hierarchy, and search for jconsole. If you see jconsole, it is because sometimes jconsole would be given as an interdependency and the path given could not be recognized. Excluding that jar will solve the issue.
Dependency Hierarchy
Interdependent jconsole
Exclusing jconsole
i was searched jdk full name.
(cos i was used when startethe 1.8.0_191 but after change laptop. its also changed to 1.8.0_282)
so i was searched at STS.
there is a string(java path) at the .factorypath.
so i change that.
its fixed now.
guys try this way~

Maven - Suppress Overriding managed version warning in Eclipse

I am using spring-boot, and experienced an error similar to the one described here. I added the following to my pom.xml.
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId><!--$NO-MVN-MAN-VER$-->
<version>1.1.0.Final</version>
</dependency>
I am overriding the validation-api 1.0.0 dependency defined in my parent pom.xml, by way of Spring boot, and this gives the pesky warning message:
Overriding managed version 1.0.0.GA for validation-api
How can I permanently suppress this warning message in Eclipse? It shows up both in my pom.xml and my problems view.
When that warning shows up, you can open the Quick-Fix menu on the warning (Ctrl+1) and select
Ignore this warning
This will add the comment on the version line, like :
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version><!--$NO-MVN-MAN-VER$-->
</dependency>
Your problem is you manually added that comment on the wrong line.
Since the project is using spring-boot, a more proper answer could be found here: https://stackoverflow.com/a/35385268/1568658
(And since I got the same issue, and the above answer also is not very complete. I would add an answer here.)
Reason of issue:
spring-boot has defined many dependencies & their versions, when you use spring-boot as parent, these dependencies got inherited, and overriding one of the dependency with a different version would get the warning, because it might break other libraries' dependencies.
Solution:
Define a property for that dependency between <properties></properties>, to specify the version.
e.g
<properties>
<reactor.version>2.5.0.BUILD-SNAPSHOT</reactor.version>
</properties>
How to find the property name:
Open your pom.xml in IDEA or Eclipse.
Ctrl + Click on the <parent> tag to open pom of parent, and need to click twice recursively to finally get to the pom file with artifactId as spring-boot-dependencies.
Once you have opened that pom, search for your dependency, e.g servlet-api, and you can see the default version.
There is a document from spring explains it better: https://spring.io/blog/2016/04/13/overriding-dependency-versions-with-spring-boot
Enter version that you need in main pom.
This warning means that you are trying to override artifact version that is defined in your main (top level) pom. Just enter version that you need in main pom and you don't even need to use <version /> in other poms for this dependency.
My issue is with lombok.jar version. I do have multiple lombok versions and eclipse somehow taking a version but it detected more versions so unable to pick it's version. So I went to maven folder (.m2) and deleted the extra versions of lombok, did maven update on project, error gone.
But I haven't provided lombok version anywhere, eclipse choose a version, don't know how.
useful ! I resolve the problem. As the module pom file declare 9.2.12.M0 while the spring-boot refer to the V9.3 . I overwrite the V9.2 in the parent pom file. follow by "Eric Wang"