Java import error - org.jdom - java

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.

Related

The import org.xxx cannot be resolved

I'm new to Java, so bear with me...
I have placed a jfreechart-1.5.0.jar file in a lib folder and wanted to do do some imports like this:
import org.jfree.chart.ChartFactory;
But VS Code is complaining: the import org.jfree cannot be resolved.
One thing I have to mention is, that I have created a copy of the project folder in order to try something. Because it worked, I have deleted the original folder and renamed the copy to the name of the original folder.
But now I have the problem that the imports do not work anymore, even it's the same code. I have "cleaned Java language server workspace" but it didn't help.
Is there anything else I have to do? Is the jar import pointing to a certain path / file?
For Maven project, you can add a dependency by clicking the + icon next to Maven Dependencies node in project view.
If your project is an unmanaged folder without any build tools. You can manage the dependencies by clicking the + icon or the - icon on the Referenced Libraries node or the items under it.
I had to reference the jar file to the project.
Surprisingly the first time it has been referenced automatically, the second time I had to do it manually...

The import cannot be resolved in JSP

Before posting this message I read tens of threads but with no success. I am trying to import a package into one of my JSP files and I keep getting the same error:
The import cannot be resolved.
I believe that something is not right with my project structure. I have tried everything, from cleanup, rebuild, even creating another project from scratch.
This is the structure of my project:
And these are the contents of my build path:
I would greatly appreciate any kind of help, this is a big blocker right now for me.
Yes, it's your project structure. Your source files are not actually under the src folder that would be listed on the Source tab of the Java Build Path property page you're showing (you can see how it's laid out that folder's contents to resemble package names). Either move the files to where they're expected or update the Source tab to point to where you're actually keeping them.
add the Java Resources/src folder to the build path or the library build path.
Thanks a lot for your answers, I have changed the project structure like in the image below and now it works:

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.

The import com.example cannot be resolved

I am trying to compile this example given by Google on the protocol buffers:
https://developers.google.com/protocol-buffers/docs/javatutorial
It comes with a ListPeople.java and AddPerson.java file along with a bunch of imports. The problem is that i am getting "The import com.example cannot be resolved" as seen in this screenshot:
http://postimg.org/image/67whg6a57/full/
This is the full path of the import com.example java file:
http://postimg.org/image/wexoc4sez/full/
and where all of my files are located:
http://postimg.org/image/4veseacpn/full/
I've tried to do the following:
Project->Clean
File->Refresh
Property->Java build path->add external JAR:
http://postimg.org/image/xjrqhievv/full/
None of these has work. What is the problem?
So this seems to be code that is missing from your project. If you press Shift-Ctrl-T and type in AddressBook, is it there?
If it is not there then it has not been generated from the example .proto files as specifiied in the Google on the protocol buffers files
You're trying to add Java source files as if they're libraries - they're not.
Add the "src" directory as a Source Path (leftmost tab in the Java Build Path settings) instead. Or if that's already a source path, try refreshing it in package explorer. Either way, you definitely don't want to have source files as libraries...

Already imported the jar files in netbeans but my source cannot find the library

I already imported the jar files in netbeans but my main java file still cannot find the methods. I am using netbeans 7.3.1 on Mac. Does anyone know how make it work?
Thank you,
I also had problem with importing classes from imported jar. It was so damn annoying...
There are couple solutions # web, (clear cache in user's AppData. or make sure to add jar's properly - by using "Add Jar/Folder..." option) but none of them worked for me.
What worked was new project and importing THE SAME (that's sad) jar files into it. So I had 2 project with exactly the same contents, but only one of them was working (compiling).
EDIT:
However, your problem is not related to mine. Root cause of your issue is the jar itself.
It contains class files in default package that is making them impossible to import.
Read here how to import class from default (unnamed) package.
hey guyes just keep your .jar files in the "C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext" it will work definitely.I have tried all the other options but i finally copied my .jar files in above path and it worked.

Categories