4

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:

  1. You have to choose a name for a build file, when trying it with the existing build file Netbeans blocks
  2. 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 libraries. But using the libraries in a new project with new source works.

Community
  • 1
  • 1
user905686
  • 4,491
  • 8
  • 39
  • 60

3 Answers3

3

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".

  • Yes, because it is assumed that the Ant script will setup the classpath correctly (for compiling and running). But there is a configuration setting ("Java Sources Classpath") where you can specify libraries to be used by the auto completion –  Sep 05 '11 at 12:33
  • @a_horse_with_no_name Can you tell me why we shouldn't make the NetBeans project folder the same as our source folder? I have run into an issue where NetBeans is showing my class files as "deleted" and I'm trying to figure out why. Is this a NetBeans "feature"? Thanks! – Brian Jun 28 '18 at 14:21
1
  1. 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.
  2. 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....

perissf
  • 15,979
  • 14
  • 80
  • 117
  • 2: Can you describe this more detailed? I already tried it with no success. – user905686 Sep 05 '11 at 12:05
  • Ok, that's somehow what I did... Selecting the jar files shows them directly under "Libraries" in the project tree, choosing the folder creates a directory under "Libraries". But neither of the versions work: When importing packages in the source files, Netbeans says `package x.y.z does not exist`. Maybe notable: The packages of the libraries show up in the project tree directly one level under the library/*.jar file. – user905686 Sep 05 '11 at 13:01
  • if you expand the library nodes you should see the loaded packages and their names – perissf Sep 05 '11 at 13:23
  • Yeah I do see the packages and the names fit, that's not the problem. – user905686 Sep 05 '11 at 13:29
0

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.

Community
  • 1
  • 1
user905686
  • 4,491
  • 8
  • 39
  • 60