简体   繁体   中英

Netbeans 11: multiple sources in a Java project

I'm trying to have multiple package hierarchies in multiple locations in a Java project. To explain further: our own software is in the packages 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. Under Project Properties , Sources , there is one setting Source Folder , which is where the com.company.V2.* hierarchy is. There is no way to say 'for com.company look in /dir1/dir2; for org.freedesktop.dbus look in /dir4/dirZ etc.' Obviously Netbeans can do this, because classes in the java.lang.* hierarchy are found, for example.

There are two consequences:

  • Maven cannot find the source when I build.
  • Netbeans cannot find the source when I control-click and shows multiple errors in the editor windows relating to methods having wrong parameters etc.

I've checked-out the two external repositories into the project root. I fixed the Maven problem by adding this to the POM:

        <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. It doesn't even fix the Maven problem properly because it is necessary to clean-and-rebuild (shift-F11) after each source change; otherwise I get a run-time error, which indicates to me that Maven isn't always finding stuff in the same place:

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

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 . So in my project pom.xml I have:

<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:

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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