How to validate Maven WAR file for AWS Elastic Beanstalk

0

I currently have an 'empty' Websocket Server here https://github.com/LanCorC/EmptyWebsocket/tree/master. Running the main class org.example.Main and visiting via localhost returns a plain HTML that reads "404 WebSocket Upgrade Failure". I want to recreate this in AWS Elastic Beanstalk.
My attempts so far lead to a log in web.stdout.log that reads:

May  6 05:46:26 ip-172-31-33-243 web[2196]: 2025-05-06 05:46:26.219:INFO:oejs.Server:main: Started @491ms
May  6 06:05:21 ip-172-31-33-243 web[3549]: Error: Could not find or load main class org.example.Main
May  6 06:05:21 ip-172-31-33-243 web[3549]: Caused by: java.lang.ClassNotFoundException: org.example.Main

With mvn clean package and java -cp target/EmptyWebsocket-1.0-SNAPSHOT/WEB-INF/classes/:target/EmptyWebsocket-1.0-SNAPSHOT/WEB-INF/lib/* org.example.Main I get different results on my IntelliJ IDE (Win10) and Github Codespaces (error in IntelliJ as in above, success in Codespaces [1][2]).
Filetree of the war file as expanded by Tomcat 11.0:

C:\Program Files\Apache Software Foundation\Tomcat 11.0\webapps\EmptyWebsocket-1.0-SNAPSHOT>tree /f
Folder PATH listing
Volume serial number is B253-ECF6
C:.
├───META-INF
│   │   MANIFEST.MF
│   │   war-tracker
│   │
│   └───maven
│       └───org.example
│           └───EmptyWebsocket
│                   pom.properties
│                   pom.xml
│
└───WEB-INF
    ├───classes
    │   └───org
    │       └───example
    │               Main.class
    │
    └───lib
            Java-WebSocket-1.5.7.jar
            slf4j-api-2.0.6.jar

Q1: What is the correct way to validate a war file for AWS EB?
I have a working Websocket Server project that I can localhost, and via Cloudflared tunnel, I can send the link out to friends to manually enter in the client webpage to play a multiplayer game. I believe AWS EB might be able to host my websocket server for free as demo 'multiplayer' for my portfolio.
Q2: Is this type of project compatible with AWS Elastic Beanstalk?
Q3: Is there a better service that I should look at for my use-case?

asked 8 days ago36 views
1 Answer
0

To validate a WAR file for AWS Elastic Beanstalk and address your specific situation:

Q1: To validate a WAR file for AWS Elastic Beanstalk:

  1. Ensure your project structure follows the standard Java web application layout.
  2. Use Maven to build your project with 'mvn clean package'.
  3. Verify that the generated WAR file in the target directory contains all necessary classes and dependencies.
  4. Test the WAR file locally using a servlet container like Tomcat before deploying.
  5. Use the Elastic Beanstalk CLI (EB CLI) to deploy and validate your application in a test environment.

For your specific issue, it appears that the Main class is not being found. This could be due to incorrect packaging or classpath issues. Make sure your Main class is in the correct package structure and that all dependencies are properly included in the WAR file.

Q2: Yes, this type of project (a WebSocket server) is compatible with AWS Elastic Beanstalk. Elastic Beanstalk supports Java applications, including those using WebSockets. However, you may need to configure your environment correctly to support WebSocket connections, which might involve setting up proper proxy settings and ensuring your application is configured to run as a web application rather than a standalone Java application.

Q3: While Elastic Beanstalk can certainly host your WebSocket server, there are other AWS services you might consider depending on your specific needs:

  1. AWS App Runner: This service might be simpler to use for containerized web applications and APIs.
  2. Amazon EC2: If you need more control over the server environment.
  3. AWS Lambda with API Gateway: For a serverless approach, though this might require some redesign of your application.

For your use case of hosting a demo multiplayer game for your portfolio, Elastic Beanstalk is a good choice as it provides a balance of ease of use and flexibility. However, make sure to review the free tier limits and potential costs as your usage grows.
Sources
QuickStart: Deploy a Java application to Elastic Beanstalk - AWS Elastic Beanstalk
AWS Elastic Beanstalk Developer Resources - Amazon Web Services (AWS)

profile picture
answered 8 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions