1

I added Lombok 1.12 jar file in classpath while I gave Lombok 1.16 jar file in libraries (while configuring build path in eclipse). Eclipse could not recognise some annotations of lombok like @Builder ( was giving compiler error). (Also @Builder was included in the main Lombok package in version 1.12)

Later I corrected gave Lombok 1.16 jar file in classpath also. @Builder annotation gets recognised this time by eclipse. Everything works well now.

This means the classpath in vm gets compared with the build path and a check is performed whether binary file (lombok.jar) is same for the classpath and buildpath both. Is my assertion correct ? Pls correct me if I'm wrongly interpreting this.

Ashley
  • 441
  • 2
  • 8
  • 27
  • In eclipse, the jar installed as agent is used for the code generation. The jar in your project is used to have the annotations accessible in your project. The agent uses a different classpath. – Roel Spilker May 30 '16 at 07:44
  • @RoelSpilker By code generation you mean jvm keeps the instructions set at one place for a particular lombok annotation so that compiler can pick up from there ? – Ashley May 30 '16 at 08:08

2 Answers2

1

build path is kind of a superset of class path,it holds class path,source code path and all resources that are dependent on project. If you have 2 different version of jars JVM will load the class from the jar which comes first in build path.This can be managed by editing (build path->configure build path->order of export). If the required class is not available in the first version it will check in 2nd version jar .if it doesn't find it at all then compilation error will be thrown

smruti ranjan
  • 741
  • 2
  • 9
  • 23
  • Thanks for answer. Can you pls provide me some link for the explaination you have given so that I can be sure? – Ashley May 29 '16 at 06:09
  • http://stackoverflow.com/questions/3529459/what-is-the-difference-between-class-path-and-build-path – smruti ranjan May 29 '16 at 06:11
  • http://stackoverflow.com/questions/6105124/java-classpath-classloading-multiple-versions-of-the-same-jar-project – smruti ranjan May 29 '16 at 06:12
  • How can you say buildpath contains classpath. Buildpath and classpath are two completely different things. The former meant for a specific project libraries setup while the latter meant for whole eclipse level (i.e adding a classpath in vmargs). – Ashley May 29 '16 at 07:18
  • Well technically buildpath doesnt conatin class path ...buildpath accumulates all tge dependencies of the project .classpath is one of those. – smruti ranjan May 29 '16 at 07:35
0

in eclipse if both jar is there in build path order them the one u want to refer give it priority order by making it to top-- Build path last tab or u can delink the lower version which u dont want to refer.

AnkurD
  • 11
  • 2
  • I'm not giving two different version in buildpath. I gave a different version of jars for buildpath and classpath. Eclipse shows me compiler error. Although the build path contains the correct version only. It is classpath that contains wrong version. @smruti answer doesn't go with my question. How does jvm resolve this conflict ? – Ashley May 29 '16 at 06:05