Netbeans can't find sources in non-standard maven project layout

纵饮孤独 提交于 2020-01-06 20:09:32

问题


I'm trying to use Netbeans 8.1 to work on a Maven project with a non-standard project structure. In my project, my sources are under src/foo instead of src/main/java. To open my project, I click File > Open Project... in the menu. Then I navigate to my project in the file browser that opens. Then I select my project and click Open. When my project opens in the Netbeans Projects tab, it does not contain any source packages. It only shows a folder labeled Dependencies and a folder labeled Project Files.

I've tried changing the location of the source folder in the project properties to fix this. I right-click on the project, click Properties, and then click Sources in the menu on the left. Then I try to edit the Source Folder value, but the value isn't editable. It's worth noting that for ant projects, I can add sources in the project properties, but for Maven this doesn't seem possible.


回答1:


Does your maven project actually build correctly? The IDE will pull the source location from your POM model. Eg.

<project>
  <build>
    <sourceDirectory>${project.basedir}/src/foo</sourceDirectory>
  </build>



回答2:


One solution is to change your project so that it uses Maven's standard directory layout. One very easy way to do that (if you have your sources under one directory), is to create symbolic link from src/main/java to src/foo:

    mkdir src/main && ln -s /path/to/project/src/foo src/main/java

If you do that, Netbeans will be able to see your sources, and you can keep your non-standard directory structure.

Possible Alternative: When searching for alternative solutions to this issue, I found that I could import the project into Netbeans as either a Java Project with Existing Sources or a Java Free-Form Project (I'm not sure which one I used). However, Netbeans won't let me do that anymore, so I'm not sure if it will always work and I'm not sure of the steps I took. If you want to try that solution, click File > New Project, choose the Java category, and choose either Java Project with Existing Sources or Java Free-Form Project. In the next window, point Netbeans to your existing sources as the location of the project. As I said above, I'm sure that this worked for me once, but I cannot use this method anymore as Netbeans shows the following error:

Project folder is managed by a project foo-project-name. Instead of creating a new project just open it. If by a chance you just deleted the project foo-project-name than [sic] restart the IDE to reuse the folder.



来源:https://stackoverflow.com/questions/35815724/netbeans-cant-find-sources-in-non-standard-maven-project-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!