Monday, July 14, 2014

Installing Java on Windows

Java is one of the most commonly used programming languages. Installing Java is straight forward. If you want to develop java applications, you need to install Java SDK and if you want to run applications developed in java, you need to install JRE. You need little more than just Java installation to make your development in Java easier. In this post, we will install the below tools required for application development in Java.
  • Java(naturally !!)
    • JDK(Java Development Kit)
    • JRE(Java Runtime Environment)
  • Integrated Development Environment(IDE)
    • Eclipse
    • NetBeans
  • Build Tools
    • Apache Ant
    • Apache Maven
  • Web servers
    • Apache Tomcat
These are the most commonly used tools in java development and the below blog post has information on where to download these tools, how to install and to check if they are installed and configured correctly.

Java


You can download the latest version of Java SDK from the below oracle site.

www.oracle.com/technetwork/java/javase/downloads/index.html

Click on ‘Download’ button highlighted in the below screen to download the latest version of Java SDK.

5

Accept License Agreement to continue to downloads.

9

Select the OS which you are using and the architecture(32 bit or 64 bit) you want to download. This will start downloading the Java SDK.

10
The Java SDK downloaded installer will be similar to the below screen shot. It may vary little bit based on Java version , operating system and the architecture.

j7


Double click on the installer to start Java SDK installation process.

After the installation is triggered, click on ‘Next’ to continue the installation.
 
j8

During the installation process, the below screen will be displayed which provides options for installation. If you want to change the default installation path, click on ‘Change’ and select the location on your hard disk at which you want to install the eclipse. If you don’t want to change the default location or if you are not sure what to do, leave it without changing.
There are options to select/deselect installation of JRE and Java source code. You can choose not to install them but it is recommended to install them, since you cant run the applications you develop without installing JRE. JRE(Java Run Time Environment) is required for running applications developed in Java. Though installing Source Code is not required, it is good to have it installed as you can look up the source code when ever you want to.
Once you are done with the customizations click on ‘Next’ to continue the installation.

 j9

Java SDK is installed.

 j12

After installing Java SDK, the installer will continue to install JRE also as you selected to install JRE while customizing the Java SDK installation.
You can select the location to install by clicking on ‘Change’ and then choosing the location on hard disk at which you want to install the JRE. Similar to Java SDK, If you don’t want to change the default location or if you not sure about what to do, leave the default location. Click on ‘Next’ to start installing the JRE.

j13

The JRE starts installing.

 j14
 
Click on ‘Close’ to complete the installation. The installation of Java SDK and JRE is completed.

j20
Now there are couple of more steps to make Java work and make it integrate better with other Java development tools.
Right click on ‘Computer’ on your desktop and select ‘Properties’ which displays the below screen. Click on ‘Advanced System settings’.
m6
Click on ‘Environment Variables’ in the below screen.
m7
Clicking on Environment Variables will display the below Window. If you want all the user accounts on your system to use Java, then run the below steps on ‘System variables’ section in the below screen. If you want only the user account with which you logged in to use Java, run the below steps in ‘User variables for YYY’ section. ‘YYY’ needs to replaced with the user account name you logged in with.
m8 
Click on ‘New’ button.
Enter the Variable name as ‘JAVA_HOME’.
Enter the Variable value as ‘C:\Program Files\Java\jdk1.8.0’. This will change based on where you installed Java.
Click on ‘OK’ to save the entry.
j1
Now select the ‘Path’ in the list of system variables and click on ‘Edit’ button. When the below screen shows up, add the below text to the existing content in the Variable value.
%JAVA_HOME%\bin;C:\Program Files\Java\jre8\bin
If you are adding this to the end of the existing value, prepend ; to the above text while adding. If you are adding this some where in between the existing content, make sure, you add this after any ; in the existing text and also append ; to the above text while adding. Click on ‘OK’ to save the modifications.
J5
Click on ‘OK’ in the ‘Environment Variables’ and ‘System Properties’ windows to save the modifications. Open the command prompt and run the below command to see if the Maven is working correctly.

Open the command prompt and run the below command to check the Java SDK and JRE installation.

java –version

If the JRE is installed properly, you will see the java version similar to the below screen shot.

 j21
Oracle site has information to guide on Java development.
http://docs.oracle.com/javase/8/


IDE

Integrated Development Environment(IDE) is a suite of developer tools which provides all the tools required by developers for developing the applications. These consists of source code editors, compilers, interpreter, debuggers, build tools, code completion features, options to refactor the code, auto generate the classes from templates, UI's for maintaining VCS etc. IDE's maximize the developer productivity since all the above mentioned features are built into one utility and will help the developers to automate several tasks. It is difficult for even seasoned developers to develop applications just using code editors without using an IDE.
One of the reason Java is very popular is due to huge tooling support it has. Java is supported by several Open source and commercial IDE's. The most common open source IDE's include Eclipse and NetBeans while some of the popular commercial IDE's are Myeclipse( built on top of eclipse and so mostly similar but with much wider support and more sophisticated support for more frameworks) and IntelliJ IDEA.
We will install eclipse and NetBeans which are the most popular open source Java IDE's.
 

Eclipse

Eclipse is free and open source IDE written mostly in Java. By installing various plugins, Eclipse can also be used to develop applications in several other programming languages like C, C++, JavaScript, PHP, Python, Scala, Groovy, Ruby etc part from Java. Eclipse was initially developed by IBM and was open sourced in 2001.Eclipse uses plugins heavily for providing all the functionality and for supporting several frameworks in Java and also support for other programming languages.It can run on Windows, Linux, Solaris and Mac OS X..
Download the latest version of eclipse from the below Eclipse download site.
https://www.eclipse.org/downloads/
eclipse
You need to select the OS you are using and download the 32 bit or 64 bit version based on the what your system supports. You need to download ‘Eclipse IDE for Java EE Developers’ .Unzip the downloaded eclipse zip folder to a location on your hard disk and launch eclipse by double clicking ‘eclipse.exe’.
121-1
  Eclipse site has more information on how to use Eclipse.
http://www.eclipse.org/users/
 

NetBeans

NetBeans is also a open source IDE written in Java and supports C, C++ and PHP development apart from Java. NetBeans was acquired by Sun Microsystems in 1999 and was open sourced in 2000. Similar to eclipse, NetBeans can also run on Windows, Linux, Solaris and Mac OS X. NetBeans supports development of several type of Java applications like Java SE, Java ME, Java FX, Web, EJB and Mobile applications out of box without installing many modules. It also provides support for build tools like Apache Ant, Apache Maven and version control systems like Subversion, Git, Clearcase and Mercurial.
NetBeans can be downloaded from the below site.
https://netbeans.org/downloads/
Since we want to set up Java environment, we can choose to download either Java SE or Java EE version of NetBeans. If you want to develop web applications, you need Java EE version and if you want to develop applications only in Java SE(core java), you can download Java SE version. Java EE version is Java SE Version + capabilities for Java EE apps, so it doesn’t do harm to download this if you are not sure. How ever if you want to develop Java ME apps, you need click the ‘Download’ under ‘All’ column.
 301
NetBeans will start downloading automatically. If it doesn’t, click on ‘download it here’ link the below page.
302
The downloaded NetBeans installer will be similar to below. The name will vary little bit based on the NetBeans version downloaded and also the flavor of the downloaded NetBeans. Double click on the installer to start installation.
303-1
The NetBeans installer is started.
304
NetBeans installer is initializing, just wait for a moment before next screen for customizing the NetBeans installation shows up.
305
In the below screen, you can select the application servers you want to install with NetBeans. GlassFish and Tomcat are the servers supported by NetBeans automatically and so select them if you want to install. If you are not sure, just select them as having them installed isn’t going to cause any harm. Then click on ‘Next >’ to continue to the next screen.
307
You need to accept the license agreement and click on ‘Next >’ to continue installation.
308
If you want to create JUnit test cases for your application(why not ?), accept the license agreement for installing JUnit and click on ‘Next >’ to continue installation. If you don’t want to install JUnit, you can select ‘Do not install JUnit’ and click on ‘Next >’ button to continue installation.
309
In the below location, you can select the NetBeans installation location on the hard disk and also the JDK path for the NetBeans to use. The installer provides the default options. If the provided Java SDK path is correct, leave it as it is else click on Browse to select the correct path. If you want to change the  NetBeans installation path, click on Browse button against it and navigate to the location where you want to install NetBeans. Click on ‘Next > ‘ to continue installation once you are done with selection of NetBeans Installation directory and Java SDK path.
311
The below screen will be displayed if you selected to install the GlassFish server. Select the location at which you want to install the GlassFish server and also select the JDK you want the GlassFish server to use. The installer provides the default paths. You can change them if you wish by clicking on ‘Browse’ button and navigating to your preferred directory. Once you are ready, click on ‘Next >’ to continue NetBeans installation.
312
In the below screen, the installation path of the Tomcat is displayed. You can change it by clicking on ‘Browse’ button and navigating to the preferred directory if you wish to, else leave it to default location suggested by the Installer. Click on ‘Next > ‘ to continue the installation.
313
The below screen displays the summary of the installation locations you selected on all the previous screens. If you want to change any of those, you can click on ‘Back’ and make the required modifications. Click on ‘Install’ to start installation of NetBeans.
314
The installer starts installing the NetBeans IDE. It will take some time to complete the installation as the installation is more than 600 MB.
315
Still installing….
316
Installing updates and JUnit.
319
The installation of NetBeans IDE is completed. Click on ‘Finish’ to close the Window.
320
Double click on the NetBeans shortcut on the desktop to launch NetBeans.
n1
More information on using NetBeans is available the NetBeans site provided below.
https://netbeans.org/kb/index.html

Apache Maven

Apache Maven is a open source build automation tool written in Java. Maven has description on how a software is build and its dependencies. Maven can be used to build and manage projects written in C#, Ruby and Scala etc. Maven uses Project Object Model(POM) for maintaining the projects. Since this was written in Java, this also requires Java to be installed on the system.
Download the latest version of Apache Maven from the below site.
 http://maven.apache.org/download.cgi
m2
Click on apache-maven-3.2.2-bin.zip. The file name may vary a little bit based on version you are downloading.
m3
The downloaded maven zip file will look similar. Since the file name contains the version number, the file name may change based on the version of Maven you downloaded.
m4
Extract maven to your preferred location on your hard disk. The extracted location will be Maven Home location. ex: I have extracted Maven to ‘C:\software\apache-maven-3.2.2’ and so ‘C:\software\apache-maven-3.2.2’ will be maven home location on my system.
m5
Since we are done  with the extraction of maven, let us check if we can run maven commands and execute them successfully. Run the below command to check if Maven is working correctly.
mvn –version
m14
Looks like maven is still not working correctly. We have extracted maven , but we didn’t do the necessary configurations for OS to recognize the maven commands. We still need to do a couple of configurations to run maven without any issues.
Right click on ‘Computer’ on your desktop and select ‘Properties’ which displays the below screen. Click on ‘Advanced System settings’.
m6
Click on ‘Environment Variables’ in the below screen.
m7
Clicking on Environment Variables will display the below Window. If you want all the user accounts on your system to use Maven, then run the below steps on ‘System variables’ section in the below screen. If you want only the user account with which you logged in to use Maven, run the below steps in ‘User variables for YYY’ section. ‘YYY’ needs to replaced with the user account name you logged in with.
m8
Click on ‘New’ button.
Enter the Variable name as ‘M2_HOME’.
Enter the Variable value as ‘C:\software\apache-maven-3.2.2’. This will change based on where you extracted the Maven.
Click on ‘OK’ to save the entry.
M10
Now select the ‘Path’ in the list of system variables and click on ‘Edit’ button. When the below screen shows up, add the below text to the existing content in the Variable value.
%M2_HOME%\bin
If you are adding this to the end of the existing value, prepend ; to the above text while adding. If you are adding this some where in between the existing content, make sure, you add this after any ; in the existing text and also append ; to the above text while adding. Click on ‘OK’ to save the modifications.
M12
Click on ‘OK’ in the ‘Environment Variables’ and ‘System Properties’ windows to save the modifications. Open the command prompt and run the below command to see if the Maven is working correctly.
mvn --version
m13
You can see the version of maven that is installed, maven home and the java version used and other system details. These may vary based on Maven, Java versions used and also based on your system specifics.
More information on Maven is available at the below site.
http://maven.apache.org/run-maven/index.html

Apache Ant

Apache Ant(Another Neat Tool) is an open source java tool for automating the software build process. It was developed to build Apache Tomcat and was released as an stand alone Apache tool on July 19, 2000. It uses XML for describing the build process and its dependencies. Similar to Java this is cross platform and can run on any OS supported by Java. Since this is developed in Java, this requires Java installation to work.
Apache Ant can be downloaded from the below site.
http://ant.apache.org/bindownload.cgi

 a1
Download the latest version of Ant Zip archive(highlighted in Green) from the downloads page.
a2
The download Ant zip archive will look similar. The name may vary a little bit based on the version of Ant downloaded.Extract it to your preferred location on the hard disk.
a3
The extracted Ant installation will look similar to below. There is no installation for Ant and the location to which the Ant is extracted is your Ant home location. Since I have extracted Ant to ‘C:\software\apache-ant-1.9.4’, that location is my Ant’s home.
a4
Now let us open the command prompt and run the below command to see if Ant is working correctly.
ant -version
a11
As you can see, ant is not working. There is nothing work with the installation. We just extracted the Ant, but the OS still doesn’t know any thing about Ant.
You need to make a couple of configurations for your system to recognize Ant installation. You need to define ANT_HOME and add Ant executable to the Path, so that OS will recognize the Ant commands whenever you run them. Right click on ‘Computer’ on your desktop and select ‘Properties’ which displays the below screen. Click on ‘Advanced System settings’.
a5
Click on ‘Environment Variables’ in the below screen.
a6
Clicking on Environment Variables will display the below Window. If you want all the user accounts on your system to use Ant, then run the below steps on ‘System variables’ section in the below screen. If you want only the user account with which you logged in to use Ant, run the below steps in ‘User variables for YYY’ section. ‘YYY’ needs to replaced with the user account name you logged in with.
a7
Click on ‘New’ button.
Enter the Variable name as ‘ANT_HOME’.
Enter the Variable value as ‘C:\software\apache-ant-1.9.4’. This will change based on where you extracted the Ant.
Click on ‘OK’ to save the entry.
A8
Now select the ‘Path’ in the list of system variables and click on ‘Edit’ button. When the below screen shows up, add the below text to the existing content in the Variable value.
%ANT_HOME%\bin
If you are adding this to the end of the existing value, prepend ; to the above text while adding. If you are adding this some where in between the existing content, make sure, you add this after any ; in the existing text and also append ; to the above text while adding. Click on ‘OK’ to save the modifications.
a9
Click on ‘OK’ in the ‘Environment Variables’ and ‘System Properties’ windows to save the modifications. Open the command prompt and run the below command to see if the Ant is working correctly.
ant -version
a10
The output displayed should look similar to above with differences in the version and the compiled date due to difference in the Ant version installed.
More information on Apache Ant is available at the below site.
http://ant.apache.org/manual/index.html

Apache Tomcat

Apache Tomcat is an open source web server and servlet container. It is one of most commonly used web containers running several millions of Java web applications across the world. It has support for clustering and High availability.
The latest version of Tomcat can be downloaded from the below site.
http://tomcat.apache.org/download-80.cgi

401
There are multiple options to download. If you want to run Tomcat as a service on your system, You need to download ‘32-bit/64-bit Windows Service Installer’. If you want to run Tomcat as a batch application, you can download 32-bit Windows.zip or 64-bit Windows.zip based on operating system you have and the architecture of Java you installed.
402
First we will install the Tomcat in service mode and later we will install it to run in batch mode. So click on ‘32-bit/64-bit Windows Service Installer’ to download the Windows installer. The downloaded executable should look similar while file name can vary a little bit based on the version of Tomcat downloaded. Double click on the executable to start the installation.
403
Click on ‘Next >’ button to continue the installation.
404
Click on ‘I Agree’ to agree the license agreement and to continue the installation.
405
The below screen has option to select the ‘Type of Installation’. By default, ‘Normal’ is selected.
406
You can select any of the other options available like ‘Full’. Based on the selection, the options below the installation type will be selected/deselected indicating which components will be installed or not installed. Click on ‘Next >’ to continue installation.
407
You can configure the Tomcat ports and provide the manager user name and password to manage the Tomcat remotely through web.
By default Tomcat runs on 8080 port in development environment and unless you have some other application running on that port , you need not change it.
You can provide a service name with which you want to view the Tomcat in Windows Services.
409
Also provide the admin and manager user name and password.You can remove any of these roles or all these roles in the ‘Roles’ textbox if you don’t want them on the Tomcat installation. Click on ‘Next >’ to continue the installation.
410
Configure the path of JRE you want this Tomcat installation to use and click on ‘Next > ‘ to continue installation.
411
Configure the location at which you want to install Tomcat and click on ‘Install’.
412
Installing Tomcat…
413
The Tomcat is installed on your system. Click on ‘Finish’ to complete the installation and launch the Tomcat.
414
Tomcat is launching.
415
A similar icon to the one highlighted below will be displayed on the task manager.
416
To check if the Tomcat is installed properly, open the browser and type in the below url.
http://localhost:8080
If you changed the port number while installing Tomcat , you should use that instead of 8080.
If the Tomcat is installed properly, you should see a similar page.
t1
You can start and stop Tomcat from the Windows services. From the Windows home, in Run, type ‘services.msc’ and select ‘services.msc’ from the list. It will show the Windows Services.
The tomcat is installed with the service name you provided while installing. You can click on ‘Stop’ to stop Tomcat and on ‘Restart’ to stop and start the Tomcat(usually for reloading the apps after modifications) and ‘Start’ to start the Tomcat.
t2
Alternatively, you can look up for ‘Apache Tomcat 8.0 Tomcat8’ in your programs and select ‘Configure Tomcat’ which will display the below Window.
In this window, you can stop, start, pause and restart the Tomcat. You can also change the startup type. If it set to automatic, it will be started immediately after the system is started and will be running in the back ground all the time. If it is set to Manual, you need to start it whenever you need it.
417
In the Java tab of the same window, you can view the Java properties of the Tomcat. You can change the JRE, if required. Also you can change the heap settings by setting the heap options in Java Options. All the normal Java options(GC algorithm, heap size  etc) can be set in the Java Options.
419

408

Now we will install the Tomcat as a batch application. But it is easier to install the Tomcat as a service and also managing the Tomcat as a service is easier for starters than maintaining it as a batch application.
Click on 32-bit Windows.zip or 64-bit Windows.zip  based on your system architecture to download the Tomcat.
The downloaded zip will be similar with slight variation in the name due to the Tomcat version downloaded. Extract the zip to your preferred location on your hard disk.
421
The extracted Tomcat folder will be similar to this.
422
To launch the Tomcat, go to ‘bin’ directory inside the Tomcat installation and double click on ‘startup.bat’.
424
The Tomcat will be launched in the command prompt.
t3
Similar to service mode, type the below link in the browser to check if Tomcat is installed and launched properly.
http://localhost:8080/
If installed and started correctly, you will seen the below local host home page.
t1
If you observe, we didn’t provide any options for JRE or ports like we did in the service mode. Obviously Tomcat used the system default JRE and also used the default port in this case. Also we don’t have the Tomcat properties Window where we had options to start, stop, pause and restart tomcat and also configure several Java options. Some of these options are not available and some options like JRE, ports etc needs to be configured in the xml files available in the ‘Conf’ folder of the Tomcat installation directory.So unless there is some thing preventing you from installing Tomcat in service mode, run Tomcat in service mode.
More information on Tomcat is available at the below site.
http://tomcat.apache.org/tomcat-8.0-doc/index.html

Conclusion

We installed the required tools for Java development. It many look little bit over whelming looking at the number of tools installed, but it is not required for every one to have all these tools installed. You may choose to use only some of these, like between eclipse and NetBeans, you may use one IDE you are comfortable with. Similar with the build tools and web server. Based on the type of applications you are using, you may not need a web server at all. Or you can still make the applications work without using any build tool or any IDE. All of these just increase developers productivity once they are mastered. So just don’t get lost or stop looking at these huge list of tools required.  Once you know how to write Java programs, you will understand the advantage of using an IDE and similarly once you start creating projects you will understand the need for build tools.Start taking it step by step !


























No comments:

Post a Comment