jar files conflict on namespaces - java

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.

Related

IntelliJ can't resolve symbol despite adding library

I am creating an external library to share code between my client/server programs. IntelliJ can't seem to import this jar file and I can't understand why, I followed all the advice I've found online.
I added the jar to my lib folder and added it as a library in my main module (it's called 'common':
This is the error (repeated on each instance of me using User or Packet). On import statements it says "package common does not exist":
I've tried invalidating caches and that didn't seem to work either. I tried this same import on a new project just to see if I was doing anything wrong and it worked perfectly on that new project so I'm not sure what's going wrong here.
EDIT:
I've noticed that this error only happens in files that are in packages within the src folder. So basically, Main can find the jar because it is only in the src folder, but RegistrationController can't because it's in src/communication.
The problem was that the shared code I was making was not in a package, just a src folder. Because of that, the code that was in my default package (src) could access the classes, but not the code in packages. To fix this, I put the shared classes in a package (com), exported them as a jar, and imported that into my project. Now, my packages can do com.Packet or com.User and get the files successfully.

JAVA Importing class from external library

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.

Java import error - org.jdom

I am attempting to edit code from an old developer.
I know it is bad practice but what she said I had to do was create a dummy project and then copy paste the packages in question modify what I need to modify then compile and copy the classes that I changed into the directory where the classes in use are stored.
So I created the dummy project and copied the packages/files into the source folder of the dummy project but I keep getting a "package org.jdom does not exist" error.
The error appears on the lines:
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
When I copied the folders/files into the source folder I copied the entire "org" directory.
You can see from my screenshot that the package is in the Project Explorer
I have several things to resolve the issue but none seemed to work.
I tried adding the "org" directory into the classpath environment variables.
I tried adding the "org" directory as a library to the project.
I have tried clearing the NetBeans cache after doing both of these but none of these 3 things worked.
Below is a screenshot of the projects src folder in file explorer
Can someone explain to me what I need to do to get this issue resolved?
I was adding the wrong files to the libraries section of my project.
I was adding the source for jdom when i should have been adding the jdom .jar file.
Thanks for the help guys.
install jdom at your library folder, there is a new version of jdom try to download it and install it in your project directory.

getting error while importing .class files in a project in eclipse

I made a java project. It has dependencies. I have the class files. So what i did i made a classes folder and put all the class files in that folder and then add that folder to my project. All the dependencies have been removed. But i think class files also have anonymous classes. SO i am getting error at that line. Here is my project structure
The error that i am getting is
The project was not built since its build path is incomplete. Cannot find the class file for com.suprema.ufe33.UFScannerClass$UFS_SCANNER_PROC. Fix the build path then try building this project
The type com.suprema.ufe33.UFScannerClass$UFS_SCANNER_PROC cannot be resolved. It is indirectly referenced from required .class files
How can i solve this error ?
Thanks
I think the problem is that the folder structure you created in the classes/ folder does not exactly match the package name of the classes you are referencing. Check the capitalization of ufe33.
By the way, it's usually better/easier to use a JAR of such dependencies instead of folders of .class files.
I solved the issue. Yes E-Riz is right that folder structure is not right. It should be small ufe33. Also i created the jar. What i did is I ran this command where i copy all the four class files.
D:\jars>jar cf myjar.jar com\suprema\ufe33*.class
It made the jar file myjar.jar. Then i simply add this jar to my eclipse project class path and the problem solved.

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 :)

Categories