Search code examples
javamacoswebsocketnetbeansentitlements

Macosx entitlements in Netbeans Java project


I have a Java application that needs to work on both Windows and MacOS which is developed in Netbeans 8.2 using JDK8.

This application needs to open a WebSocket, but I'm getting 'Operation not Permited' exception in MacOS, in Windows it works fine.

I have implemented the WebSocket server using 'org.java_websocket.server.WebSocketServer' class.

The stack trace looks like this:  

     Operation not permitted
     java.net.SocketException: Operation not permitted
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.Net.bind(Net.java:425)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
        at org.java_websocket.server.WebSocketServer.run(WebSocketServer.java:325)
        at java.lang.Thread.run(Thread.java:748)

I have been reading about possible solutions, but there are very few. One possible solution, taken from an XCode post, could be to add an entitlement file to the application to get the rights to access the network, but I don't know how to do it in a Java project with Netbeans and I do not find any documentation about it.

Edit 1

I think the problem is that the application is launched from another application using the Process.Run method. If I launch it directly it opens the websocket correctly.


Solution

  • Maybe you can try enabling the Incoming Connections and the Outgoing Connections from the app that launches your Java process. In the XCode project you have to go to your Project Settings > Signing & Capabilities > App Sandbox and enable the Network checks.

    Hope that helps.