3

I have such code:

public static void main(String[] args) throws Exception {
    System.out.println("ALPN class: " + ALPN.class);
    HelloWorldClient client = new HelloWorldClient("localhost", 10009);
}

This gives such output:

ALPN class: class org.eclipse.jetty.alpn.ALPN
Exception in thread "main" java.lang.IllegalArgumentException: ALPN is not configured properly. See https://github.com/grpc/grpc-java/blob/master/SECURITY.md#troubleshooting for more information.
    at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:163)
    at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:136)
    at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:124)
    at io.grpc.netty.GrpcSslContexts.forClient(GrpcSslContexts.java:94)
    at btcduke.node.ln.HelloWorldClient.<init>(HelloWorldClient.java:35)
    at btcduke.node.ln.HelloWorldClient.main(HelloWorldClient.java:76)
Caused by: java.lang.ClassNotFoundException: org/eclipse/jetty/alpn/ALPN
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at io.grpc.netty.JettyTlsUtil.isJettyAlpnConfigured(JettyTlsUtil.java:34)
    at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:153)
    ... 5 more

HelloWorldClient uses grpc, and it looks grpc is trying to load ALPN class dynamically. Am I right? This class can't be find, so I have error message. But please take a look,that I have access to this class (I print this class in first line). Do anyone knows why it happens this way? I have no idea :/

I toretically solved this issue by adding VM argument "-Xbootclasspath/p:" to run configuration option, but I don't understand why I needed to do this and also I don't think this is elegant method.

C D
  • 145
  • 2
  • 8
  • Did you read the part in the error message that starts with "ALPN is not configured properly"? – Mick Mnemonic Dec 29 '17 at 21:38
  • Do you think that `org/eclipse/jetty/alpn/ALPN` is the proper name for that class? – laune Dec 29 '17 at 21:41
  • Before any more guesses are being made: look at the error message of the ClassNotFoundException thrown by the forName method call. It shows the string of the name as given in that call. Slashes are wrong - you should have periods there to separate package names. – laune Dec 29 '17 at 21:44

2 Answers2

3

Documented at https://www.eclipse.org/jetty/documentation/jetty-9/index.php#alpn-chapter

For Java 8 up to 1.8.0_242 included.

You MUST use the alpn-boot provider for your specific JVM, as it modifies OpenJDK classes to enable support for ALPN.

See ALPN to OpenJDK version list:
https://www.eclipse.org/jetty/documentation/jetty-9/index.html#alpn-versions

This alpn-boot-<ver>.jar requires use of the -Xbootclasspath/p: option on the JVM command line.

You will also use the jetty-alpn-openjdk8-server-<ver>.jar on your normal Server classpath for your specific version of Jetty server.

For Java 8 from 1.8.0_252 and later (including Java 9+).

For Java 8 from 1.8.0_252 included and later, this provider uses the standard OpenJDK ALPN APIs introduced in Java 9 (see below) that have been backported to 1.8.0_252 and does not require the -Xbootclasspath/p: option on command line

For this operational mode, use the jetty-alpn-java-server-<ver>.jar artifact on your server classpath.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • That's not OP's problem, though. – laune Dec 29 '17 at 21:44
  • That is exactly the problem the OP is having. The class `org.eclipse.jetty.alpn.ALPN` isn't loaded the way you think it is. It has a boot classpath dependency that is preventing it from being loaded normally. – Joakim Erdfelt Dec 29 '17 at 21:49
  • The error message for the ClassNotFoundException lists the argument of Class.forName. I don't think that a class name has slashes as separators between package names. It may come from a configuration file, though. – laune Dec 29 '17 at 21:52
  • Thanks. I added VM argument "-Xbootclasspath/p:" to run configuration option. Issue is gone, but I don't understand why I needed to do this and also I don't think this is elegant method. Maybe this is because for some reason, this class have to be loaded before load my main classes? – C D Dec 29 '17 at 21:56
  • @CD the `-Xbootclasspath/p:` option loads classes even before the JVM's own classes. This is done by the ALPN layer to modify the JVM SSL classes to add ALPN support. (The first time ALPN support existed in the JVM is Java 9) – Joakim Erdfelt Jan 02 '18 at 20:33
  • Hi guys, Im running into same problem, may I know how did you add this VM variable? is it like this ? java -Xmx8192m -Xms4096m -Xss1024m -Xbootclasspath/p: -jar mayJar.jar ? – Tamer Saleh Feb 11 '18 at 06:27
  • @TamerSaleh see https://www.eclipse.org/jetty/documentation/9.4.x/alpn-chapter.html#alpn-versions – Joakim Erdfelt Feb 12 '18 at 13:09
  • I am getting this error in Java11. I am not allowed to use `-Xbootclasspath/p:` as it's been removed - any thoughts? – emraldinho Mar 29 '21 at 13:20
  • since -Xbootclasspath/p removed from java 11 ,any idea how to solve this problem? – vanshu Jul 14 '21 at 02:33
  • @vanshu it's best to open new questions for specific questions like yourself - the answer above has the details for Java 9+. – Joakim Erdfelt Jul 14 '21 at 11:23
1

If you received an error message "ALPN is not configured properly" or "Jetty ALPN/NPN has not been properly configured", it most likely means that:

ALPN related dependencies are either not present in the classpath or that there is a classpath conflict or that a wrong version is used due to dependency management.

Looking closely at the provided stacktrace, it reveals that you need to configure "ALPN" properly

Caused by: java.lang.ClassNotFoundException: 
org/eclipse/jetty/alpn/ALPN
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at 
io.grpc.netty.JettyTlsUtil.isJettyAlpnConfigured(JettyTlsUtil.java:34)
fabfas
  • 2,200
  • 1
  • 21
  • 21