Google Guice (pronounced as “juice”) is a lightweight dependency injection framework for Java 5 and above. Dependency injection is a design pattern whose core principle is to separate behavior from dependency resolution. Guice allows implementation classes to be bound programmatically to an interface. Refer.
Java must be installed first. For Google Guice 3 Eclipse plugin refer to this link. And for building the application you will need to install Maven. The Google Guice version used is 3.0 and an Eclipse version used is Eclipse Juno v4.2.
- Google Guice 3 Hello World Program
Once the JDK and Maven setup is done, create a directory in C drive. This will be your workspace with eclipse to write Google Guice code. Create a new Maven project with Eclipse. Refer. Specify details for HelloGuice Project.
The HelloGuice will be created in Eclipse and it will have /src/main/java/ folder for writing java source.
Find the Source Code on GitHub: Google Guice 3 for HelloGuice Application.
Once the code is checkout from GitHub and added into Eclipse, the project structure should look like below screenshot.
Now, run the Maven command from this Project folder to build the project, mvn clean install.
And then, run the HelloGuice program by executing the Main class,
HelloGuice3which has the Main method. This will give you the result on a console as below.
So here we are done with the first Hello Guice program with Google Guice 3.