简体   繁体   English

Netbeans 11:Java 项目中的多个源

[英]Netbeans 11: multiple sources in a Java project

I'm trying to have multiple package hierarchies in multiple locations in a Java project.我试图在 Java 项目的多个位置有多个 package 层次结构。 To explain further: our own software is in the packages com.company.V2.* .进一步解释:我们自己的软件在包com.company.V2.*中。 I now want to add these external repositories:我现在想添加这些外部存储库:

but unlike in previous versions of Netbeans, it seems there is no way to specify multiple directories for these separate packages.但与以前版本的 Netbeans 不同,似乎无法为这些单独的包指定多个目录。 Under Project Properties , Sources , there is one setting Source Folder , which is where the com.company.V2.* hierarchy is.Project PropertiesSources下,有一个设置Source Folder ,这是com.company.V2.*层次结构所在的位置。 There is no way to say 'for com.company look in /dir1/dir2;没有办法说'对于 com.company 看 /dir1/dir2; for org.freedesktop.dbus look in /dir4/dirZ etc.'对于 org.freedesktop.dbus,请查看 /dir4/dirZ 等。 Obviously Netbeans can do this, because classes in the java.lang.* hierarchy are found, for example.显然 Netbeans可以做到这一点,因为例如在java.lang.*层次结构中的类被发现。

There are two consequences:有两个后果:

  • Maven cannot find the source when I build. Maven 构建时找不到源。
  • Netbeans cannot find the source when I control-click and shows multiple errors in the editor windows relating to methods having wrong parameters etc. Netbeans 在我控制单击时找不到源,并在编辑器中显示多个错误 windows 与具有错误参数的方法等有关。

I've checked-out the two external repositories into the project root.我已将两个外部存储库签出到项目根目录中。 I fixed the Maven problem by adding this to the POM:我通过将其添加到 POM 中修复了 Maven 问题:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>dbus-java/dbus-java/src/main/java</source>
                            <source>kk-dbus-nm-java/src/main/java</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

but this doesn't fix the editor window errors.但这并不能修复编辑器 window 错误。 It doesn't even fix the Maven problem properly because it is necessary to clean-and-rebuild (shift-F11) after each source change;它甚至不能正确修复 Maven 问题,因为每次源更改后都需要清理和重建(shift-F11); otherwise I get a run-time error, which indicates to me that Maven isn't always finding stuff in the same place:否则我会收到一个运行时错误,这表明 Maven 并不总是在同一个地方找到东西:

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: org.freedesktop.dbus.connections.impl.DBusConnection.addSigHandler
    at com.company.V2.net.Wifi.openBusConnection(Wifi.java:38)
    at com.company.V2.net.Wifi.<clinit>(Wifi.java:23)

One way of fixing all this would be to use symlinks so that Maven and Netbeans see all packages in one hierarchy, but regrettably we have to support developers on Windoze / NTFS and in typical MS fashion, the simple matter of symlinking becomes ridiculously complicated under Windoze.解决这一切的一种方法是使用符号链接,以便 Maven 和 Netbeans 在一个层次结构中看到所有包,但遗憾的是我们必须支持 Windoze / NTFS 上的开发人员,并且以典型的 MS 方式,符号链接的简单问题在 Windoze 下变得异常复杂. I have created the symlinks and they solve all the problems given above, but I would prefer a 'proper' solution and not one involving a hacky workaround.我已经创建了符号链接,它们解决了上面给出的所有问题,但我更喜欢“正确”的解决方案,而不是涉及到 hacky 解决方法的解决方案。

For the sake of anyone else looking, here is the best I have so far.为了其他人看,这是我迄今为止最好的。

My project really only depends directly on org.freedesktop.NetworkManager , which in turn depends on org.freedesktop.dbus .我的项目实际上只直接依赖于org.freedesktop.NetworkManager ,而后者又依赖于org.freedesktop.dbus So in my project pom.xml I have:所以在我的项目 pom.xml 我有:

<repositories>
  <repository>
    <id>kk-dbus-nm-java</id>
    <name>NetworkManager</name>
    <url>file:///home/myself/projects/kk-dbus-nm-java</url>
  </repository>
</repositories>

and

<dependency>
  <groupId>kkdev.dbus</groupId>
  <artifactId>org.freedesktop</artifactId>
  <version>1.0-KKDev</version>
</dependency>

then /home/myself/projects/kk-dbus-nm-java/pom.xml is:然后/home/myself/projects/kk-dbus-nm-java/pom.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>kkdev.dbus</groupId>
    <artifactId>org.freedesktop</artifactId>
    <version>1.0-KKDev</version>
    <packaging>jar</packaging>    
    <dependencies>
        <dependency>
            <groupId>com.github.hypfvieh</groupId>
            <artifactId>dbus-java</artifactId>
            <version>3.2.0</version>
        </dependency>
    </dependencies>    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM