We will show you how easy it is to use MINA, running a very simple example provided with the MINA package.
The first thing you have to do is to setup your evnvironment when you want to use MINA in your application. We will describe what you need to install and how to run a MINA program. Nothing fancy, just a first taste of MINA...
First, you have to download the latest MINA release from Downloads Section. Just take the latest version, unless you have very good reasons not to do so...
Generally speaking, if you are going to use Maven to build your project, you won't even have to download anything, as soon as you will depend on a repository which already contains the MINA libraries : you just tell your Maven poms that you want to use the MINA jars you need.
After the download is complete, extract the content of tar.gz or zip file to local hard drive. The downloaded compressed file has following contents
On UNIX system, type :
$ tar xzpf apache-mina-2.0.7-tar.gz
In the apache-mina-2.0.7 directory, you will get :
| +- dist +- docs +- lib +- src +- LICENSE.txt +- LICENSE.jzlib.txt +- LICENSE.ognl.txt +- LICENSE.slf4j.txt +- LICENSE.springframework.txt +- NOTICE.txt
- dist - Contains jars for the MINA library code
- docs - Contains API docs and Code xrefs
- lib - Contains all needed jars for all the libraries needed for using MINA
Additional to these, the base directory has couple of license and notice files
Running your first MINA program
Well, we have downloaded the release, let's run our first MINA example, shipped with the release.
Put the following jars in the classpath
- Log4J 1.2 users: slf4j-api.jar, slf4j-log4j12.jar, and Log4J 1.2.x
- Log4J 1.3 users: slf4j-api.jar, slf4j-log4j13.jar, and Log4J 1.3.x
- java.util.logging users: slf4j-api.jar and slf4j-jdk14.jar
IMPORTANT: Please make sure you are using the right slf4j-*.jar that matches to your logging framework. For instance, slf4j-log4j12.jar and log4j-1.3.x.jar can not be used together, and will malfunction. If you don't need a logging framework you can use slf4j-nop.jar for no logging or slf4j-simple.jar for very basic logging.
On the command prompt, issue the following command :
$ java org.apache.mina.example.gettingstarted.timeserver.MinaTimeServer
This shall start the server. Now telnet and see the program in action
Issue following command to telnet
telnet 127.0.0.1 9123
Well, we have run our first MINA program. Please try other sample programs shipped with MINA as examples.