Netbeans 7:如何从现有源正确创建 Java 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7307419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Netbeans 7: How to create Java project from existing source correctly?
提问by user905686
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
我想创建一个新的 Netbeans 项目(在这个结构内),使用现有的
- 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:
使用 Netbeans 指南从现有源创建项目,我设法导入源和测试文件,但存在问题:
- 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.
- 使用现有的构建文件 Netbeans blocks 尝试时,您必须为构建文件选择一个名称
- 创建项目后,
.lib/
无论是否进入Properties/Libraries 下的文件夹,Netbeans 都找不到库包。
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.
至于问在这里,我想创建一个Git仓库项目,但建议的解决方案并没有对我来说有效(Git并不想克隆到非空目录...),我怀疑这会与帮助图书馆问题等
EDIT 1
编辑 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)!
不知何故,它可以创建一个新的 Netbeans 项目,然后向其中添加库并导入库的包。但这在从现有源创建项目时不起作用(然后 Netbeans 找不到包)!
EDIT 2
编辑 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.
它似乎更复杂:当我创建一个新项目时,它也不起作用,将源文件夹更改为源所在的目录(我想从中创建一个项目)并添加库。但是在具有新源代码的新项目中使用这些库是可行的。
回答by a_horse_with_no_name
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)
1) 使用自由形式的项目。当你这样做时,你可以指定你的 build.xml 供 NetBeans 使用(然后它不会抱怨,因为 NB 不会创建它自己的 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".
2) 不要使用存储项目的目录作为“NetBeans 项目文件夹”。NetBeans 项目文件夹仅存储“NetBeans 内部”内容,无需将其与您的源代码混在一起——尤其是当它们处于版本控制之下时。您可以将任何目录用于“NetBeans 项目文件夹”。
回答by perissf
- 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
- AFAIK 您无法导入构建文件。您可以在打开项目之前重命名它,或者告诉 NB 创建一个不同名称的构建文件。
- 在项目属性中可以一一选择库,指向lib文件夹中的jar
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....
EDITED 2. 右击左窗格中的项目节点,选择属性。项目属性窗口将打开。有关屏幕截图,请参见此处:http: //netbeans.org/kb/docs/java/project-setup.html。在左侧的类别窗格中选择库。然后在中间的“编译”窗格中,按“添加 JAR/文件夹”按钮并添加 jar。您可以尝试添加整个文件夹,我还没有尝试过,但可能会起作用....
回答by user905686
Ok, it seems that Netbeans is a little buggy there.
好吧,看来 Netbeans 在那里有点问题。
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.
尽管我在不知何故不起作用之前重新加载了项目或重新启动了 IDE。甚至发生了 Netbeans 生成一些无限目录的lib/lib/lib/lib/...
情况。
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 notselect the original lib folder in the project properties/libraries field. Maybe that was the problem before.
经过一些尝试,它与“来自现有源的项目”一起工作。我使用“添加 JAR/文件夹”选项添加了库,选择了所有 jar 文件并且它工作正常。我并没有选择在项目属性/库场原lib文件夹。也许这是以前的问题。