Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 11 support #21

Closed
Dmunch04 opened this issue Dec 27, 2019 · 26 comments
Closed

Java 11 support #21

Dmunch04 opened this issue Dec 27, 2019 · 26 comments

Comments

@Dmunch04
Copy link

Hi. I'm trying to create an engine.io server with Java JDK 11.0.5. Altough I seem to get errors about the AsyncListener class, which was also removed after Java 8. Are there any plans to make it support Java 8+?

@trinopoty
Copy link
Collaborator

AsyncListener is a part of the java servlet api. Are you sure you have the proper dependencies?
What server are you using?

@Dmunch04
Copy link
Author

Dmunch04 commented Dec 27, 2019

Here's the error I'm getting:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/AsyncListener
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at org.TeamName.ChatApp.Server.Server.<init>(Server.java:43)
	at org.TeamName.ChatApp.App.main(App.java:15)
Caused by: java.lang.ClassNotFoundException: javax.servlet.AsyncListener
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 11 more

Process finished with exit code 1

And the code that was the reason I got those errors:

EngineIoServer server = new EngineIoServer();

And here's my dependencies in my pom:

<dependencies>
  <!-- java-express -->
  <dependency>
    <groupId>com.github.Simonwep</groupId>
    <artifactId>java-express</artifactId>
    <version>caef9738b4</version>
  </dependency>
  <!-- - -->

  <!-- socket.io client -->
  <dependency>
    <groupId>io.socket</groupId>
    <artifactId>socket.io-client</artifactId>
    <version>1.0.0</version>
  </dependency>
  <!-- - -->

  <!-- engine.io server -->
  <dependency>
    <groupId>engine.io</groupId>
    <artifactId>server</artifactId>
    <version>1.0</version>
  </dependency>
  <!-- - -->

  <!-- socket.io server -->
  <dependency>
    <groupId>socket.io</groupId>
    <artifactId>server</artifactId>
    <version>1.0</version>
  </dependency>
  <!-- - -->
</dependencies>

And as you might notice, both the engine.io and socket.io server has been built from your sources by me. So yeah I've just built them myself to try and fix the error.

@trinopoty
Copy link
Collaborator

Ah I see.
This library is not meant to be used as a standalone server. It can only be used within a web server such as Tomcat or Jetty.

@Dmunch04
Copy link
Author

Aha. I wanted to use it together with java-express, but I guess that's not possible?

@trinopoty
Copy link
Collaborator

I guess not unless you can run java-express inside a java web server.
This library has heavy dependencies (basically based around) the java servlet api.

@Dmunch04
Copy link
Author

Well could you please provide a simple example of how to use Jetty to end up with a socket.io server?

@trinopoty
Copy link
Collaborator

Please look at this example.
It can be run on any server viz. Tomcat, Jetty, etc.

@Dmunch04
Copy link
Author

Well I can't create a new EngineIoServer class instance, without getting that error

@trinopoty
Copy link
Collaborator

You would need to add dependency on javax:javaee-api:7.0. But, like I said, it'll only run in a server implementation such as Tomcat, Jetty, etc.

@Dmunch04
Copy link
Author

So even for you, if you just do

EngineIoServer server = new EngineIoServer();

you'll also get that error.

And would I add that dependency to the engine.io-server or my project's pom?

@Dmunch04
Copy link
Author

Because I can see that in the example you sent, it does that:
https://github.com/jeevaengg21/engine.io/blob/master/src/main/java/com/jee/engineio/sample/EngineIoServlet.java#L32

@Dmunch04
Copy link
Author

Also how would I run the server? I can't seem to find any exact location where they run the server. I might just be blind

@trinopoty
Copy link
Collaborator

Yes, you need to add the dependency in your project. But, simply adding it in will bring a whole lot of problems too unless you're deploying your project on a java server.
Alternatively, you can use a Jetty embedded server. You can find examples for that here.

@Dmunch04
Copy link
Author

Yeah. That was kind of what I was hoping that you had a simple example for. I found this: https://github.com/socketio/engine.io-server-java/blob/master/docs/using.rst#jetty-server
But I don't know if that's still gonna work?

@Dmunch04
Copy link
Author

Like a simple Jetty example with engine.io and socket.io

@trinopoty
Copy link
Collaborator

I found a complete Jetty example here.

@Dmunch04
Copy link
Author

Looks promising. Altough I found this again:

private final EngineIoServer mEngineIoServer = new EngineIoServer();

would it work in that context then?

@trinopoty
Copy link
Collaborator

trinopoty commented Dec 27, 2019 via email

@Dmunch04
Copy link
Author

Great! I'll try and get that to work. Altough one thing I also need to know is, will a engine.io server be able to communicate with a socket.io client? Server is Java and client is JavaScript.

@trinopoty
Copy link
Collaborator

trinopoty commented Dec 27, 2019 via email

@Dmunch04
Copy link
Author

Yeah I already have a copy. But like in the example you sent above, I don't really see the engine.io being used anywhere, except the servlets? But I don't see the servlets being used anywhere except the StartupListener which doesn't get used anywhere. Idk if that's how it's supposed to work, but I can't really see how the servlets would ever be instantiated

@trinopoty
Copy link
Collaborator

trinopoty commented Dec 27, 2019 via email

@Dmunch04
Copy link
Author

Ah okay I see. I'm a bit new to Java servers. Anyway, I would just create the socket.io server in a servlet right?

@Dmunch04
Copy link
Author

Together with the engine.io server

@trinopoty
Copy link
Collaborator

trinopoty commented Dec 27, 2019 via email

@Dmunch04
Copy link
Author

I can't seem to get it to work. The server is being hosted, but the servlet isn't get initialized. Do you have some place where I could contact you, perhaps a Discord account?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants