Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Java Program How to programmatically start Jetty on port 80 as non-root user
    primarykey
    data
    text
    <p>I'm trying following progam:</p> <ol> <li>If i use SUDO java to run everthing is fine, but I don't want to use SUDO</li> <li>without SUDO i get following error: <code>SocketException: Permission Denied (as its PORT 80)</code></li> </ol> <p>Using jetty documentation, I get this to work using command line where i change </p> <ol> <li><code>jetty-setuid.xm</code>l -- Put user-name is non-root user</li> <li><code>start.ini</code> -- Change to EXEC and passing <code>etc/jetty-setuid.xml</code> as first parameter</li> <li><code>jetty.xml</code> -- To have port number as 80</li> </ol> <p>then I still do sudo as non-root user -- like -> <code>sudo java -jar start.jar</code> Jetty starts on port 80 as non-root user.</p> <p>I want to ACHIEVE the same using JAVA Program. Any help/comments are appreciated.</p> <pre><code>package my.package; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.nio.SelectChannelConnector; public class JettyTest { public static void main(String[] args) throws Exception { Server server = new Server(); System.out.println("Created new server, now going to start"); SelectChannelConnector connector0 = new SelectChannelConnector(); connector0.setPort(80); //on port 80 connector0.setMaxIdleTime(30000); connector0.setRequestHeaderSize(8192); server.setConnectors(new Connector[]{ connector0 }); server.setHandler(new MyHandler()); //simple hello world handler server.start(); System.out.println("started server on port 80"); server.join(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload