Netbeans 7: How to create Java project from existing source correctly?
Starting with the following file structure:
doc/
lib/
src/%java-like structure%
test/%java-like structure%
build.xml
I want to create a new Netbeans project (inside this structure), using the existing
- build file
- sources
- libraries
- other files
With the Netbeans guide to create a project from existing source I manage to import sources and test files, but then there are problems:
- You have to choose a name for a build file, when trying it with the existing build file Netbeans blocks
- After creating the project, Netbeans doesn't find the library packages in
.lib/
whether entering the folder under Properties/Libraries or not.
As asked here, I want to create the project from a git repository, but the suggested solution doesn't work for me (git does not want to clone into a non-empty directory...) and I doubt this would help with the library problem etc.
EDIT 1
Somehow it works to create a new Netbeans project, then add libraries to it and import the packages of the libraries. But this doesn't work when creating a project from existing sources (then Netbeans doesn't find the packages)!
EDIT 2
It seems to be even more complicated: It also doesn't work when I create a new project, change the source folder to the directory where the sources are (from which I want to make a project of) and add the libra开发者_运维技巧ries. But using the libraries in a new project with new source works.
You have two choices:
1) Use a freeform project. When you do that, you can specify your build.xml to be used by NetBeans (then it won't complain as NB will not create it's own build.xml)
2) Don't use the directory where your project is stored as the "NetBeans Project Folder". The NetBeans project folder only stores "NetBeans internal" stuff and there is no need to mix that up with your sources - especially when they are under version control. You can use any directory for the "NetBeans project folder".
- AFAIK you cannot import the build file. You can rename it before opening the project, or tell NB to create a build file with a different name.
- In the project properties you can select the libraries one by one, pointing to the jars in the lib folder
EDITED 2. right-click on the project node in the left pane, select properties. The project properties window will open. See here for the screenshots: http://netbeans.org/kb/docs/java/project-setup.html . In the categories pane on the left choose libraries. Then on the "compile" pane in the middle press the button "Add JAR/Folder" and add the jars. You can try adding the whole folder, I haven't tried yet but may work....
Ok, it seems that Netbeans is a little buggy there.
Though I reloaded the project or restarted the IDE before it somehow didn't work.
It even occurred that Netbeans produced some infinite directories with lib/lib/lib/lib/...
or so.
After some attempts it worked with the "project from existing source". I added the libraries with the "Add JAR/Folder" option, selected all jar files and it worked. I did not select the original lib folder in the project properties/libraries field. Maybe that was the problem before.
精彩评论