Different jar file in classpath and buildpath in Eclipse - java

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.

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

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.

Related

How do I add modules to the Eclipse Oxygen module path for a project?

I have a project that today has several jars as "Referenced Libraries". I'd instead like to add these as automatic modules on the module path so I can require them in my module-info.java. How do you add jars to the module path in Eclipse Oxygen?
Here is how I got it to work (first few steps are for those that haven't set up Eclipse for JDK 9 usage yet):
Install JDK 9 (9.0.1 was available at this time from Oracle).
Configure Eclipse to run with JDK 9 by modifying eclipse.ini by adding these lines and restart Eclipse:
-vm
<fullPathToJDK9>/bin
--add-modules=ALL-SYSTEM
In your project properties, go to Java Build Path, and under Classpath, expand the twisty for each jar that you want to be a module. You should see a new entry called "Is not modular". Click on it and click the Edit button. Under the Modular properties dialog that opens, check the box "Defines one or more modules". Click OK and it should now say "Is modular" and it will be moved up to Modulepath.
Apply your changes and your module-info.java should be able to require those jars. Use the name of the jar without any version identifier or .jar suffix, e.g. for myLib-1.0.jar, use requires myLib;.
By the way, I had a problem with Maven generated jars with names like appName-1.0-SNAPSHOT.jar. I could not use them in module-info.java because it couldn't find it. Getting rid of the SNAPSHOT part made it possible to use it.

java compilation error in eclipse helios

I have executable jar file which is running perfectly when i am double clicking on it. but when i extracted the source code from jar file using jdk gui and trying to execute it in eclipse helios it is displaying the following errors
The project was not built since its build path is incomplete. Cannot find the class file for ControlPoint. Fix the build path then try building this project
The type ControlPoint cannot be resolved. It is indirectly referenced from required .class files
I tried refreshing the source folder, changing the output folder of eclipse, but nothing worked for me.
Can anyone please help.
I think you need to specify the right JRE in your buildpath. Also, you need to check if all the required libraries are added to the buildpath.
You won't be able to build and run until classpath is fixed. Check whether a library containing ControlPoint class is in class path, if not, then add it there.
You can find the library this way
http://www.findjar.com/index.x;jsessionid=EBF627F4D0BAEC200B8DF6DE50C3C47B?query=ControlPoint
If the ControlPoint class is in the sources that you extracted then make sure that this source folder is in the sources paths, if not add it there in project properties -> java build path -> source

Scala eclipse-plugin Project unmanaged dependencies of referenced projects not on classpath after upgrade from 2.9 to 2.10

I recently tried to upgrade from Scala 2.9 to 2.10 and ran into the following difficulties:
I have two scala eclipse-plugin projects. The first one has some unmanaged libraries on it's build path. This project compiles and runs fine.
The second project depends upon the first project and some Java project configured via eclipse-plugin dependencies.
Here I get four not very helpful compile errors. Three times the following
SBT builder crashed while compiling. The error message is 'bad symbolic reference. A signature in XSBInterRunner.class refers to term interprolog in value com.declarativa which is not available. It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling XSBInterRunner.class.'. Check Error Log for details. de.wwu.sdpn.wala Unknown Scala Problem
Plus another dumping the class path which actually does not contain the corresponding library.
If I manually add the missing libraries to the second project the first project isn't found anymore. Even though it was on the dumped class path previously.
When compiling the projects from the command line via SBT using a more or less equivalent setup everything works fine.
I've also tried to reconfigure the dependencies not to use the eclipse-plugin mechanism for dependency management but directly added the other project to the build path but this also didn't help. Reimporting the projects to a clean workspace also didn't help.
The problem exists both with the 3.0.1 and the nightly version of the scala-ide plugin on Eclipse 4.2 and 4.3.
Any idea how to resolve this issue? Is there any way to find out why the libraries are missing from the class path?
From the description, it looks like the unmanaged library is not exported from the first project. Verify that in project properties > Java Build Path > Order and Export, the checkbox next to the library is selected. It is needed to make jars visible to other projects.

Getting NoClassDefFoundError when using common.lang.StringUtils in android java code?

I am getting this error:-NoClassDefFoundError wherever the code is using StringUtils class or methods .I have correctly added the jar files to the code and is not showing any kind of error in my code(Using Eclipse Indigo).
Is there any kind of point I am missing out. I have used this jar file in other projects but they worked properly.
Please help If any one is getting similar kind of problem?Thanks
Yes, this because of your .jar file didn't import properly. Follow below steps -
Place your .jar file in your project's libs folder .
Import it into your project. And, GoTo project -> properties -> Java build path -> order tab.
Check, whether your .jar file checked and placed in order of 1st. This is the main thing.
Hope these steps helps you. Have a look at below image -
Note that the build classpath is different from the runtime classpath. You must add the required JARs to both.
It's one of the things I don't like in Eclipse...
EDIT: To add JARs to the runtime classpath: in Eclipse, double click the plugin.xml file associated with your project. On the Runtime tab there is a Classpath category. From there, you can add JARs to the runtime classpath.
Here is a screenshot to illustrate this:
Are the jar files in a lib folder or a libs folder?
Newer SDKs require the jar files to be in a libs folder.
I do not know how you execute your code, but it clearly means that the jar is not properly added to your classpath, especially if your code compiles in Eclipse.
Add it to your classpath -or re-check it is well added- when executing and it should work.
Right click on project, Select Build Path -> Configure Build Path and Select Libraries tab. Then with add Jars, add the jar in question.(if you are using eclipse)

NoClassDefFoundError on external library project for Android

I use eclipse for Google Android development.
I've created a library project ([x] Is Library in the Android-settings), which includes an external jar-file (Referenced Libraries). This library project are referenced in another Project (the actual project which will use the library project). This is done by add the project under the Android-settings.
the source compiles but if I want to execute it on the device, I get the NoClassDefFoundError for a class which is inside the jar-file which is included in the library project.
Edit: The jar-file ist added to the exported entries ([x] my.jar on the Order and Export-Tab from the library project)
Is there a clean way to get this working?
It has been clearly stated in offcial API here:
A library project can include a JAR library
You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file
The jar lib must be manually added to the dependent application project's build path, not only the library project build path itself.
Update from SDK r17:
This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:
Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)
For those who followed the steps(even check the projects in "Order and Export") and still have the java.lang.ClassNotFoundException in the API 17, the final step is to check that your compiler does not run with Java 1.7. If is 1.7 then you should change it to 1.6 for all your projects. After that it will ask to rebuild all the projects and successfully ran on my phone :)
To change the java compile version in eclipse, this is located in: Project properties > Java Compiler > Compiler Compliance level: 1.6
Go to project properties -> build path-> libraies
If you see your jar files like this
snmp4j.jar - e:\software\jars
Its may your problem
Add libs folder in your project and copy jar file in that folder. Right click jar file and go build path -> add to build path. Then you can see your jar as
snmp4j.jar - project_name/libs
Its worked for me.
I had two projects using the same library: one working, the other one crashing with java.lang.NoClassDefFoundError.
After nothing else helped me, I looked into the file project.properties in the root directory of my project.
The working project had the android.library.reference line (the last line below), the crashing one did not:
# Project target.
target=android-17
android.library.reference.1=../my-library-project
I manually added the line and it started working!
(Yes, I did try both (project) properties -- java build path -- projects and (project) properties -- java build path -- order and exports -- nothing helped.)
PS By the way, "project properties" has also the "project references" tab. No idea if it would work.
I had a minor issue when I upgraded to ADT17 where my libs weren't being imported properly. Turns out this is because my librarys were being linked as dependancies from my lib folder not libs!
Seems librarys have to be in the libs folder from now
I had a similar problem and non of the solutions out here fixed it.
Short version: the JAR was compiled in Java 1.7 and could not be found by Dalvik.
We build an internal JAR that we share across backend and mobile clients with Maven. The problem ended up being that the JAR was compiled with Java 1.7. Androids dalvik only supports Java 1.5 and 1.6. This is why everything works fine in Eclipse as it's not compiled to dalvik at this point.
We even specified the target and source version in the Maven compiler plugin to compile with Java 1.6. This did not work because only JDK 1.7 was installed on the build machine. A small note at the bottom of the Maven page gave us the hint: Note: Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version.
To see if you have this problem as well, rename your *.jar file to *.zip unpack it, and look in the MANIFEST.MF file for the Build-Jdk: parameter to see what Java version actually compiled your JAR.
Another thing to pay attention to is library package names.
If you are using ADT21 and you happen to have libraries that have the same package name, there will be error during compile but it will still compile and run in Eclipse, giving you an APK that is missing some of the resource classes. Hence the crash when you run the app.
If you compile it with ANT then you can see the compile error that says two or more libraries use the same package name.
To fix this, rename your library project by using Android Tools -> Rename Application Package. Then everything will go back to normal.
It took me almost entire day to figure this out...

Categories