JAVA Importing class from external library - java

I am trying to use the SimpleRegression class (link).
I first imported the .jar file as external jar into my project and I can see it is imported.
When I try :
import org.apache.commons.math3.stat.regression.*;
I have no error message, so the jar file is correctly imported,
but when I import specifically the class I need:
import org.apache.commons.math3.stat.regression.SimpleRegression;
I get the message that SimpleRegression cannot be resolved.
Can somebody tell me what I did wrong?
I downloaded the package from here .
thanks for your help

If your are using NetBeans the way to add a library to your class path is to go to
File-Open Project-Select Your Project Name-Right Click on Libraries-Click Add Jar/Folder and then select your jar file. Then you must wait for it to do it's background scan before your run with the new imports. It is possible that an error occurred when you imported the jar into your project so try removing the jar now, then follow the steps above to add it to your class path. If it still doesn't work after that the jar file may be corrupted.

Related

org.cementj.base.ValueObject package in our project?

I want to use class "org.cementj.base.ValueObject" in our project but its not find any jar regarding this class.
I want to use package of this jar And know how to import this package in eclipse.
First you download the cementJ Api.Here is the link for download
https://sourceforge.net/projects/cementj/postdownload?source=dlp
Extract the zip and add jars in your project.

jar files conflict on namespaces

I have two jar file in my project dependencies (gwt-dev-2.4.0.jar and commons-codec-1.5.jar) while both has class with this namespace "org.apache.commons.codec.binary.Base64" so when importing this package I get java.lang.NoSuchMethodError exception because wrong select jar for import. any idea to solve this? remember that both jar file is needed on my project.
No response! great. too bad that importing package dose not consider jar filename but I figure it out my problem by adding the source code of right package in my project.

jars added to WEB-INF/lib doesn't get recognized when I try to import them : says the package doesn't exist

I have added org.apache.commons.fileupload and org.apache.commons.io package into the WEB-INF/lib directory of my project based on google appengine. But when I try importing in the servlet files the compiler/IDE gives an error that this package doesn't exist. Why is that ?
The jar files added :
What can be the reason I am getting this error ? What should I do to solve this problem ?
You might also have to add them to your project's classpath.
for eclipse:
Right click the jar, select build path and add it to the build path, then try again.
for netbeans:
in the project properties window click libraries in the left panel. In the right panel add it to the compile classpath
General solution , whenever you get package does not exist then there are 2 things, 1- Its not at all present 2) its present but still the error is thrown.
The solution to this is to just add the jar to the classpath [so that your app finds it during compilation,execution)
I would suggest you to try Maven . Maven is a nice way by which you can organize this in a systematic way.
If the IDE gives the problem then update the jars in IDE project class path :)

Adding Reflections library to a Eclipse project

I am trying to add Reflections library to an Eclipse Java project to use it for my needs. The problem is that although I have added reflections-0.9.9-uberjar.jar to my project's lib folder, and also to the Build Path (in fact it appears also under "Referenced Libraries"), the builder seems not to recognize it, so this line for example gives me an error:
Reflections reflections = new Reflections("net.iberdroid.gameserver.cmds");
"Reflections cannot be resolved to a type"
If I try to import org.reflections it says that it cannot be resolved neither.
Any ideas?
Thanks a lot in advance,
The quick and dirty way: open the reflections-0.9.9-uberjar.jar and extract all the jars within it to your lib folder. Then add those jars to the build path.
The more correct way would be to setup your project as a maven project and setup all the dependencies there. Take a look inside META-INF folder of the uberjar.
You may import a class:
import org.reflections.Reflections;
or all the classes in a package:
import org.reflections.*;
But you can't import a package:
import org.reflections; // looks for a class named "reflections" in the package "org"
Note that, with an IDE like Eclipse, you almost never import anything, because the IDE does it for you. Type "Refl", then Ctrl-space, and Eclipse will suggest to use Reflections and add the import for you. Or use "Reflections" without importing it, then hit Ctrl-Shift-O, and Eclipse will organize the imports by adding all the necessary imports and removing unnecessary ones.
EDIT:
The reflections-0.9.9-uberjar.jar file is not a Java library (a jar containing classes). It's a jar containing other jars (and which should thus be a zip file to avoid the confusion). You must unzip the jar and put all the libraries it contains into the build path.

Java class file not on classpath

I've tried opening class file in eclipse that I have copied pasted from the jar that I have imported into the project and am receiving this as first error:
org.eclipse.core.runtime.CoreException: The class file is not on the classpath.
Evidently I have included the class file incorrectly into my project. I need to use this class file to access Java applet. Suggestions please
Rather than trying to copy the class file into your project, you should reference the Jar that the class you want is part of.
Go to: project->properties->java build path->libraries tab->add external jars...
Right Click on project > Maven > Update Project
worked for me :)

Categories