OK I give up. I've been trying to do this for the past two hours I googled how to add external source to eclipse, how to import, how to add to build path etc. and I must say there is absolutely nothing that clearly states how do you do this.
I want to add a directory with some Java classes. I downloaded it from github. It has a package some.package.name in its header.
I tried drag and dropping it to my project, adding it via build paths, using the import button. I tried changing the package names.
I always get this "RED X" icon next to the folder names ( these folder names are called like the package string in the headers ). This isn't even annotated so I do not know what am I even doing wrong. Why doesn't eclipse accept these sources? They are already in the project tree I do not understand this.
Can somebody actually tell me how you are supposed to do this? And why is this so complicated? Why would people create a IDE with I suppose a million lines of code and then make it be so hard to do the simplest thing?
Sorry for the rant but I am seriously starting to hate Java.
Related
I am new to Java and this is my essay to pass java. I found a template that I want to test, but the error is too strange for me to understand.
I must work in Netbeans ID 13 and the picture shows it all. But to me... I have the idea that I have everything on the same place. See here
I hope someone can help me to get on the right track.
Make sure the package and the directory names are both in lowercase. So 'com.mycompany.test1' not 'com.mycompany.Test1'. If the java source files are in the same package, then an import is not needed.
There might be something wrong within Options.java too. If so, please share the source code of it.
An external java library is treated as "package only containing non Java resources" (as indicated by the white icons as opposed to brown; the description in quotes is taken from here). When I try to import the library it cannot be resolved, so it seems it really isn't being recognised (in other words it's not just a case of eclipse showing wrong icon).
Two people have commented that my screenshots are not helping, so let me explain the intention behind them. The first one above is to show the difference between how my libraries are displayed. Htmlparser is a folder with .java files just like SPMF and works fine. Commons-lang and vecmath are .jars. SPMF cannot be resolved when I try to import it. The reason the screenshot is cropped this way is to highlight that all of the folders in SPMF are showing white which apparently means they are not recognized.
This is only the second time I'm using an external library, but I think I did everything the same as the first time.
This screenshot is intended to show how SPMF is added at the moment.
The library I am trying to add is SPMF - more specifically the Hierarchical Clustering algorithm. This is only a minor component of SPMF but it's the best Hierarchical Clustering solution I could find. It works fine if I just import it into a new project. So I could just bodge it by moving my code into that project if I can't get it going otherwise.
I presume that if a package can form a standalone project then it can also be used as an external library - or am I wrong?
I'm sure it's a stupid mistake I'm making but I've had no luck with google. This is the nearest I could find; Refresh seems the only applicable solution and it doesn't help.
Edit, SPMF is also available as a jar, it's missing some features but not the ones I need. I've been able to add the jar and the import the algorithm I need. It's enough of a workaround for me to move on and keep going. But it's not a solution and the question remains open.
So I made a package, lets call it dev.example.project for example purposes. all my other packages extended off of that one, with names like dev.example.project.handler or dev.example.project.assets. But I decided to go back and change the dev.example.project package's name to something else, like dev.betterexample.project.
I thought it would be a simple matter of renaming all the other packages and import statements so no errors would happen, but right after i changed the name, all the packages in my project turned white and became inaccessible. I changed the name back to what it originally was, but when i opened Eclipse again, some packages and files were simply not there.
I spent a lot of time on this project, someone help?
Depending how exactly you did that renaming, various things could have gone wrong.
Remember: you can always go in and work outside of eclipse. Close it, open a file explorer and create directories that use the names you want to use. Then move files manually to their target directories. If you want to, open them in another text editor and fix the package lines. When you now open eclipse, do a refresh and full rebuild. Things should be fine then.
That is probably not the most elegant solution, but it always works. And more importantly, you are in full control of everything that happens!
And for the record: the real answer to avoid catastrophic loss of code is to use a source code management system such as git. And to then push your changes constantly out to that "backup" facility.
Tried to google but got hundreds of unrelated issues regarding testing. I guess I'm missing a crucial keyword to reduce the number of hits to something that is relevant for me.
I have a class in src/test-integration/java which i need to run, since it is a tool for extracting test data from an database. It's basically just a little script in the main method.
However when I try to "run as java application" in Eclipse it says: Error: Could not find or load main class x.y.z.MyClass
I know it has worked before, but not sure how I got it to work.
Sorry for any missing information, please feel free to ask for more.
Any ideas of what I'm missing?
Added the whole full path to the java class in the Java Build Path properties in Eclipse and deselected "allow output for source folders" and selected it once again (don't know if that did something, but I include it anyway).
I've come across quite an odd problem with eclipse.
I was working on a project and I right clicked on a method call declared in another class and used Eclipse's handy find declaration in project (saves me quite a bit of scrolling) to run a search for that specific method declaration. Right as it should my search pane pops up with a link to the method declaration. So I click the link, the other file the method is declared in is opened automatically, and poof the Java file I had searched from disappears from my editor tabs.
So I say to myself, "damn this old version of eclipse (Indigo) has some bugs...now I've got to go reopen my file and get back to my spot...GREAT!". But when I open the file, it is treated like a plain text file. All the text is the same color, and the outline won't work!!!
So I solved the problem whilst I was typing the above up and decided to post the answer since it isn't a nice clean solution..and I doubt one exists.
Okay so file wasn't being recognized by eclipse..
So I open the file and do a Save As, and save it under another name in the same package.
Then, I went to my test code and right clicked on a method call that was declared in the file that eclipse had buggered up, and went to search for declaration in project.
Sure enough two results popped up, one in the newly saved as file, and one in the old one.
I clicked on the old one, and still plain text...no difference.
But then I clicked on the new one, and my highlighting was back!
So then I just deleted the old file and refactored.
I think somehow eclipse made the file disappear without properly closing it...just my guess, glad I resolved this nice and quickly, hopefully anyone who has the same issue can be helped by this.
This happened to me a couple of minutes ago. Trying to close/open the projet, restarting eclipse did not work for me.
The steps I used were:
Pick another Java file (same package) right next to the bogus one (make sure syntax highlighting works on this one)
Choose 'Save As' and override the bogus one.
Verify that the bogus one now has proper syntax highlighting
Use git checkout -- to retrieve you original file
Et voilĂ !