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)
Related
I'd like to know how I can add Java libraries to an Eclipse project on a development machine so that they can be added to an Eclipse project without causing errors when someone who has the library in a different location. For example, one developer might add an external JAR in C:\Java, but another might have the same JAR somewhere else. (Where's C:\Java on Mac OS?) I thought I might set the CLASSPATH environment variable, but I can't figure how to add an external JAR from the CLASSPATH environment variable. I'd like to do this so that it works with any workspace. Is this possible?
This is specifically for use with Anypoint Studio, but I think the same problem would exist with any Eclipse-based IDE.
In general, it's recommended to either embed JARs directly into the project, usually in a /lib folder of the project, as described here; or to use a tool like Gradle or Maven to manage dependencies, both of which have nice plugins to support their use in Eclipse.
Another alternative would be to use a Classpath Variable to refer to the JAR(s), which abstracts the physical location so that it can be set on a per-workspace basis.
I think the best way to add library to eclipse project is creating a directory - lib in your project directory. Then add the whole lib to you eclipse class path. You can follow these step to add a lib to class path -
Right click on project and select properties
Select Java Build Path
click Add Library and create User Library
Now add External Jars to this library create at step 3.
By this a .classpath file is crated in you project directory and the CLASSPATH problem will be resolved
I guess the best way to do that would be using Maven, or a similar build system that can construct your Classpath base on dependencies.
You can add the dependencies to your pom and having the jars in your local maven repository in the machine.
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Because in any other approach you will need to maintain everything manually, and when having different OS the path will change.
Eclipse is just the IDE that will help to write code and assemble the project (JAR, WAR, ... ). You can add your external jars from wherever you want, and when you want to export your project (with eclipse) you may choose to package the required libraries into the jar.
However, I recommend always to use maven (or something like ) to avoid this kind of problems.
Part1:(import .jar file as library in Eclipse)
You make a new project to Eclipse(name:Project1)
When you open it you see JRE System Library[java version something]
1.right click on JRE System Library
2.Go->Build Path->Configure Build Path
3.You can see (Up right Corner the button[add jars or add external jars]
*Here i advise you to choose the first(add jars) but..
*First copy(or move) the (name).jar inside the project((example):Project 1)
*Now you can add it with the button(add jars).
*In this way when you finish your project the (name).jar will be
imported inside the project(If you export it as a .jar from Eclipse)
..Now you can call any method of (name).jar just(import it into the class
you want to use and call it)
I am struggling with this issue for some time now and I think it is time that I appeal to the SO community.
When creating a new Android Project in Eclipse I am trying to reference an external project [for the time being, it is a simple class with a function that returns a string]. I have tried adding a reference to the project itself, I have tried exporting a .JAR file [adding it to the libs folder] but none of these solutions work, though at compile time the classes are seen, at run time I get the dreaded NoClassDefFoundError.
Because the JAR file is present both in the filesystem and the .classpath file, I believe there might be an issue with the way I exported the JAR.
I am not sure why it doesn't work or what the proper workflow is for adding such [non-Android] modules to a project. Any help would be greatly appreciated!
I have come across this issue in a lot of SO questions but I could not find any solutions that would work
I've actually had the same problem before. There are a couple things you can try.
Make sure that in the project properties for your external project that you have the the "Is Library" checked in the Android tab.
Then export the project as a jar file. (make sure you don't include and files other than the actual java class files. No AndroidManifest.xml etc...)
Include the jar file into your other project in the "libs" folder like you were doing before.
and you should be able to reference the class from the jar now.
If that still doesn't work, you might have an ordering issue, so right click the jar file, and select "Build Path" -> "add to build path", then go to the project properties of your non-library project and select Java Build Path -> Order and Export and move the jar file to the top of the list.
Hopefully this helps!
Cheers
I've created a simple plugin project in eclipse 3.5 that just stores third-party libraries for the use by other bundles in an eclipse RCP application. Worked as expected: I edited the manifest, exported the required packages and added the libraries to the build path (project build path as well as manifest build path).
Some days later I added another jar to that project, did the same steps (exporting a package, adding the library to the build path(s)) but this time I can't import classes from that exported package in other bundles. The package was clearly selectable on the manifest editor but import statements in classes just taunt me with curly red lines. Importing classes from other packages exported by the bundles still works, only classes from the newly added lib remain invisible.
Has anyone has an idea what I might have missed? I'm pretty stuck and have no idea how to convince google to show me the solution to that ugly issue...
Check the following:
Make sure they are in the Build
Configuration -> Order and Export
area, and they are check for export.
Make sure you have the packages
exported in the manifest (PDE Tools
-> Open Manifest -> Runtime tab)
In the same place as above, make
sure the JAR files are in the
manifest classpath.
(as Al says
below), make sure the build
properties has your jars marked for
exclusion (though this is not likely
your issue as you are getting errors
compiling).
If all of this is done (and it's still not working), do a clean build an restart eclipse. Sometimes the Eclipse gets a little confused about this and a restart helps.
Check the build.properties to see if the bin.includes includes your newly added Jar. Without it, it won't be exported by the build process, and thus won't be able to use it in dependent bundles.
I have a project in Eclipse, that inculdes some files with data(not in classpath), and I want to pack this project to the runnable jar-file, but the problem is, that after I pack it to the jar, it's not located there. How can i add it to the jar?
Create an additional source folder and put your files in there. Unless explicitly told to Eclipse only jars things up in the classpath.
If you cannot do that due to some unmentioned restriction then please revise your question.
I would try making sure it's in the src folder. Eclipse tends to add everything in there into the JAR. If that's not an option, let me know in the comments.
Did you actualised your project's content in Eclipse before making the jar?
Right click on package explorer -> refresh.
I'm having a problem with imports in one of my java applications.
I've Taken a working JSP out of one Eclipse project, Jar'd up all the classes from that project and put it into a new project.
In the new Project I've imported the jar file generated from the original, and pasted the jsp code into a new JSP document.
I'm getting "The import XX could not be resolved errors".
Anyone one have any idea how to diagnose this, everything seems to be in order.
I have an issue like this once in awhile. Try removing the JAR, rebuilding, and adding the JAR again. This should fix it.
It's an Eclipse bug.
Edit: The above answer is assuming the jar is actually on the build path.
When you say "I've imported the jar file" you mean you have copied it or put it in the classpath?
When you add a Jar file, instead of Import, right click on the project and choose "Add External Library" or "Add External Jar"
It sounds like the jar you imported doesn't appear in your build path. Try right-clicking the project, select Build Path > Add External Archives...
This should put a reference to your jar in the project build path.
Check inside the Jar (just open it from the build path) and see if the paths are correct. If you have foo.Bar as something else than foo/Bar.class that might be it.