diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod index 256ed05d56a..bd99ae571c2 100644 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod +++ b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod @@ -5,7 +5,7 @@ Enables the ALPN (Application Layer Protocol Negotiation) TLS extension. [depend] ssl -alpn-impl/alpn-available-${java.feature.alpn} +alpn-impl/alpn-available-${runtime.feature.alpn} [lib] lib/jetty-alpn-client-${jetty.version}.jar diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index b3353978fd0..ef74db738eb 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -1507,9 +1507,10 @@ public class StartArgs properties.setProperty("java.version.platform", Integer.toString(ver.getPlatform()), source); // features built into java. - properties.setProperty("java.feature.alpn", Boolean.toString(ver.getPlatform() >= 9), source); - properties.setProperty("java.feature.jpms", Boolean.toString(ver.getPlatform() >= 9), source); - properties.setProperty("java.feature.loom", Boolean.toString(ver.getPlatform() >= 16), source); + // TODO: Remove in Jetty 10+ + properties.setProperty("runtime.feature.alpn", Boolean.toString(isMethodAvailable(javax.net.ssl.SSLParameters.class, "getApplicationProtocols", null)), source); + // TODO: Remove in Jetty 10+ + properties.setProperty("runtime.feature.jpms", Boolean.toString(isClassAvailable("java.lang.ModuleLayer")), source); // @deprecated - below will be removed in Jetty 10.x properties.setProperty("java.version.major", Integer.toString(ver.getMajor()), "Deprecated"); @@ -1531,6 +1532,32 @@ public class StartArgs } } + private boolean isMethodAvailable(Class clazz, String methodName, Class[] params) + { + try + { + clazz.getMethod(methodName, params); + return true; + } + catch (NoSuchMethodException e) + { + return false; + } + } + + private boolean isClassAvailable(String clazzname) + { + try + { + Class.forName(clazzname, false, this.getClass().getClassLoader()); + return true; + } + catch (ClassNotFoundException e) + { + return false; + } + } + public void setRun(boolean run) { this.run = run;