• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Cant cast from lombok var to String eclipse IDE

 
Ranch Hand
Posts: 680
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator





I am importing lombok in the pom.xml file.

But eclipse is complaining cannot cast from var to String. Is this an eclipse ID problem. Do I need to set something up in my eclipse ID.


Thanks for any help.
 
Saloon Keeper
Posts: 13367
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you already install Lombok into Eclipse? Just declaring the Maven dependency is not enough.

Anyway, what's the point of declaring a variable of type var anyway, if you're going to cast it to String immediately afterward?
 
Master Rancher
Posts: 4052
56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You would probably want to spell this "lombok".

What library are you using here?  Where is jsonValue() defined?  Does it actually return a String, or something else?  If it's not a String, the IDE may well be able to tell that it's something that can't possibly be successfully cast to a String.
 
Tony Evans
Ranch Hand
Posts: 680
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks, its legacy code, that i am now taking over. I had a feeling it was an eclipse IDE problem.  I am guessing I need to add a lombok plugin. There is a lot of code that needs to be looked at. But I want to sort this out first.

Thanks Tony
 
Saloon Keeper
Posts: 24499
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that's not "Eclipse" complaining. It's the project builder within Eclipse that's complaing. Eclipse is an IDE used to develop programs, not something that you "program into" (unless you're writing add-ons for Eclipse itself).

Since you have a POM, shut down Eclipse, open a command line window, "cd" to the directory containing the project POM file and type the following command:
Then, just to make sure Lombok gets pulled into your local Maven repository, type this:


Now restart Eclipse. You may need to refresh the project, but that should add all of the Maven project dependencies to the Eclipse project definition and it should be all happy.

Note that if "mvn compile" fails, then you probably have a version of Lombok that doesn't match what you are trying to do and you need to check the Lombok documentation to see if you need to change your application code or if you need to change the Lombok version requested in your Maven dependency.
 
Stephan van Hulst
Saloon Keeper
Posts: 13367
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim, you'd still need to install Lombok into Eclipse separately, because it needs a separate compiler/code analyzer that knows to convert Lombok magic to plain Java.
 
Tony Evans
Ranch Hand
Posts: 680
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks for everyones help.  

I ran the install to install on the jar lombok-1.18.10.jar Lombok onto eclipse. In my eclipse.ini it created

-javaagent:C:\Users\teven\eclipse\jee-2021-06\eclipse\lombok.jar

I ran mvn eclipse:eclipse which ran ok.

But mvn compile

failed with incompatible types: lombok.var cannot be converted to java.lang.String.

I am not sure what else I can do.  Its installed on the IDE, its part of the mvn build in the POM. Is there another step I need to carry out.
 
Sheriff
Posts: 22504
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is there a need to use var? From what I've just read, it's similar to Java's own var. And if you can't use that (because you need to keep using Java < 11), just use String instead.
 
Tim Holloway
Saloon Keeper
Posts: 24499
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Tim, you'd still need to install Lombok into Eclipse separately, because it needs a separate compiler/code analyzer that knows to convert Lombok magic to plain Java.



So. It's providing Eclipse IDE plugins and compile-time code rewriting.

The Lombok website is very short on details. Apparently you're supposed to watch the video. I never watch the videos. If there isn't enough supporting documentation, I don't want it. Oh wait - there's a miniscule link to someone else's website for non-video information. It has detailed information on installation and use and I highly recommend using it. It also tells why you'd even want to use Lombok, which is more than the authors are willing to do, minus the video.
Of concern, it isn't available via the Eclipse Marketplace, the sample install dialog is for obsolete versions of Eclipse, and - most fatally - it doesn't even rate a Wikipedia article.

OK. Here's the process as I gathered from the third-party docs:

1. Download the Lombok jar manually and execute the lombok.jar file. That will cause it to search for your installed copy(ies?) of Eclipse and install itself (probably copy the JAR to Eclipse's plugins directory).

2. To use when building via command-line tools such as Maven, you need to include a dependency for Lombok in the POM - AND - a repository element indicating Lombok's own private Maven repository. You may be able to define the Lombok rep in your master Maven configuration file, but without checking I won't guarantee it.

Again, I don't know if Lombok works with current releases  of Eclipse. If still no success, uninstall Lombok per the directions. Check your eclipse/plugins folder to make sure no files with "lombok" in there name are present and re-install.
 
Rob Spoor
Sheriff
Posts: 22504
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:1. Download the Lombok jar manually and execute the lombok.jar file. That will cause it to search for your installed copy(ies?) of Eclipse and install itself (probably copy the JAR to Eclipse's plugins directory).


If I recall correctly, it puts the JAR file in the root of the Eclipse installation, and updates the ini file. I haven't done this recently (and refuse to do so unless I really need to), so maybe I remember it incorrectly.

2. To use when building via command-line tools such as Maven, you need to include a dependency for Lombok in the POM - AND - a repository element indicating Lombok's own private Maven repository. You may be able to define the Lombok rep in your master Maven configuration file, but without checking I won't guarantee it.


What's wrong with https://mvnrepository.com/artifact/org.projectlombok/lombok?

Again, I don't know if Lombok works with current releases  of Eclipse. If still no success, uninstall Lombok per the directions. Check your eclipse/plugins folder to make sure no files with "lombok" in there name are present and re-install.


I've used it with either Eclipse 4.6.3 or 4.15, I can't remember which one. I think I used https://www.baeldung.com/lombok-ide, because it looks familiar. Indeed - no official Lombok site...
 
Tim Holloway
Saloon Keeper
Posts: 24499
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:
What's wrong with https://mvnrepository.com/artifact/org.projectlombok/lombok?



Nothing, as long as it's being kept up to date,. Often, however, the official Maven repo versions of projects with their own repos end up unmaintained and 20 versions out of date. So care is recommended.

I've used it with either Eclipse 4.6.3 or 4.15, I can't remember which one. I think I used https://www.baeldung.com/lombok-ide, because it looks familiar. Indeed - no official Lombok site...


I can't even remember how old that would be. Eclipse no longer uses astronomical names and its versioning is based on release date now.

The problem here is that unlike most Java, Eclipse plugins do tend to rot if they're not kept in sync with the latest version of Eclipse. So having worked once is no guarantee. In the case of annotation processors that do code rewriting and/or reweaving, changes in the Java compiler makes gives potential for even more breakage.
 
Rob Spoor
Sheriff
Posts: 22504
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The current version is either 4.19 or 4.20. If I recall correctly there are either 2 or 4 releases a year, so 4.15 isn't that old.
 
Tim Holloway
Saloon Keeper
Posts: 24499
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:The current version is either 4.19 or 4.20. If I recall correctly there are either 2 or 4 releases a year, so 4.15 isn't that old.



Ah. I was going by the info on the splash screen. Didn't realize that they were still running internal numbering.

Auto-update seems to have broken on my copy of Eclipse, and it's 4.16 - identifies itself as 06/20.
 
Rob Spoor
Sheriff
Posts: 22504
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eclipse by default doesn't (or at least, didn't, maybe it has changed) allow updating to new "major" versions. That can be changed pretty easily:
  • Open Windows -> Preferences -> Install/Update -> Available Software Sites
  • Check "Latest Eclipse Simultaneous Release" (or whatever the label is for https://download.eclipse.org/releases/latest)

  •  
    Tim Holloway
    Saloon Keeper
    Posts: 24499
    167
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It didn't matter. I had a horrible blend of Eclipse/JEE and Eclipse/C++ with Arduino mixed in and manual updating broke it altogether. I ended up nuking one of my 2 legacy installations and installing from scratch. Hope I didn't lose too many plugins.

    I think that I maybe did get update notifications once, but obviously not recently.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic