In Eclipse, go to the File Menu, select New, and then select Java Project.
Name the project 17S-PS5-Chat110
Under JRE, we recommend going with "Use default JRE".
Click Finish and you have a new Java project!
For reasons unknown Eclipse disables JavaFX in new projects and defaults to the older user interface libraries of Swing and AWT. We'll want to make Eclipse accessible. We'll also disable AWT/Swing so that we avoid accidentally importing classes from those libraries instead of JavaFX.
1. Right click on the project.
2. Go to Build Path > Configure Build Path...
3. Select the Libraries tab
4. Expand the JRE System Library entry
5. Select Access rules and press Edit...
6. Add an access rule for JavaFX:
Rule Pattern: javafx/**
7. Add an access rule for AWT:
Rule Pattern: java/awt/**
8. Add an access rule for Swing:
Rule Pattern: javax/swing/**
Your Access Rules should look like this before pressing OK and OK again to save them:
The connection the chat client you build makes with the Chat110 server are using a modern technology called WebSockets. Java does not have built-in WebSocket support yet, so we will make use of Project Tyrus, a free, open source library that does. This is the most "official" Java library for WebSockets as it is sponsored by Oracle, the company who builds Java.
Java libraries you can add to your project are stored in JAR files just like those you submit in COMP110.
First, let's make a folder in our project where we will store this library file.
1. Right click on your project and select New > Folder. Name it vendor. This is an idiomatic name that programming projects tend to use which indicates the contents of this folder were created by third parties or vendors. In days past, most libraries were commercial. These days, it is more common to rely upon high quality, open source libraries which are free.
Now let's go download the libraries as JAR files. We could provide a direct link to this file, and we actually do at step 6, but if you want to see the full detail of how we get there, continue on. Feel free to poke around along the way.
2. Navigate to the Project Tyrus website: https://tyrus.java.net/
3. Click Download. Scroll all the way to the bottom. Look for "if you need just client implementation, you should use the Tyrus Standalone Client" and click the link.
4. Next click the big link Browse Central For "org.glassfish.tyrus.bundles : tyrus-standalone-client : 1.13.1"
5. Here you'll see a confusing list of files. A list like this is typical for many Java libraries so let's break down what you're seeing.
First look for the 3 files that end with exactly ".jar". Each has a similar name except one has no suffix, another has a suffix of "-javadoc" and the last of "-sources".
These are the 3 JAR files we care about. You will only need the JAR file with no suffix. This one contains the compiled Java code your project will depend on. The JAR file with the suffix of "-javadoc" contains documentation files that explain all of Tyrus' classes and their methods. The JAR file with the suffix of "-sources" contains the Java source code files for all of the Tyrus library. If you'd like to add the javadoc or sources JARs to your project you are free to. Try googling for "adding a sources JAR to Eclipse" and StackOverflow will have you covered.
The other files, that do not have JAR extensions, are a variety of signatures/hashes that are only there so that you can verify the authenticity and correctness of the JAR files you download. These are beyond the scope of 110 and will make more sense once you take a first course in security.
6. Go ahead and download tyrus-standalone-client-1.13.1.jar and move it to the vendor folder in your project.
7. Finally, back in Eclipse, select your project and either press F5 or right click on the project and select "Refresh". You should now see the JAR file in the vendor folder.
8. Right click on the JAR file and select "Build Path" > "Add to Build Path"
The "build path" is where Java will look for classes that are imported. What you've done in this series of steps is brought in a 3rd party library to a project. Now you can import classes from this library and make use of it! To keep the focus of this project focused for the whole class, we are providing support code to everyone that makes use of this Tyrus library you just imported and hides some of its details.
Your code must be setup in the correct packages for grading to work. In this project we will organize code into a few different packages.
comp110.chat.packets - This is where support code provided by us will be. In this project no support code will be hidden from you. In the next step we'll show where to download the source code from.
comp110.chat.messages - This is where the classes which represent the various kinds of messages will be.
comp110.chat.tools - This is where tools we build to test our code in the process of making the client will be.
Right click on the source folder (src) and select New > Package. Add the four packages above. BE SURE THE PACKAGE NAMES MATCH EXACTLY!
You can find the starter code on the project's page on GitHub: https://github.com/comp110/17S...
GitHub is a site that hosts open source software projects. It is great to get familiar with GitHub as you will see it frequently in your career moving forward.
There are four files you'll need to get started. For each, browse to them in GitHub, look for the "Raw" button on the right hand side just above the code, click it and copy/paste into a new Class you create with the exact same name in Eclipse:
Got these four files? You should be all set! This is how you can begin projects on your own, too.