0

I am attempting to handle system signals in my Java application such that USR1 and USR2 will trigger specific debugging / diagnostic workflows in a running environment.

Using the following main App:

package org.test.signals;

import sun.misc.Signal;

public class App {

    public static void main(String[] args) {

        Signal.handle(new Signal("USR1"), new MySignalHandler());
    }
}

Where the Handler is

package org.test.signals;

import sun.misc.Signal;
import sun.misc.SignalHandler;

public class MySignalHandler implements SignalHandler {

    public void handle(Signal sig) {

        System.out.println("Got: " + sig.getName());
    }
}

In Eclipse, I see the following warnings on Both Signal and SignalHandler:

Access restriction: The type 'Signal' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_151\jre\lib\rt.jar')

With a quick search, I found that this fix seems to work, and the warnings go away..

However.. This is a maven managed project; each time I refresh / update the Maven project, my .classpath file is reverted to it's previous configuration, and the warnings return.

I can reproduce this using a brand new Maven Project using the Eclipse wizard.

The smallest pom.xml

<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>org.test</groupId>
    <name>signals2</name>

    <version>0.0.1-SNAPSHOT</version>
    <artifactId>signals2</artifactId>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>
</project>

Instead of updating the libraries in Eclipse, what changes can I make to my pom.xml to fix this?

What is different about the JRE System Library added in the method metioned in the link above, and the library used when building via maven?

Matt Clark
  • 24,947
  • 16
  • 62
  • 114

1 Answers1

0

I was just looking into this more, and discovered what this error actually means - and why it appears.

The Warning disappears after using Eclipse to re-add the System Libraries, because this added my Eclipse workspace default, which was the JDK, not the JRE.

In my case, the sun.misc.Signal classes exist in the JDK, but do not exist in the JRE.

Matt Clark
  • 24,947
  • 16
  • 62
  • 114