Step by Step Web Service guide

To learn more on web services let’s first understand the concept of the service oriented architecture.

SOAP based Webservice

SOAP based Webservice

What is Service Oriented Architecture?
Service Oriented Architecture is a software design principle and architectural design pattern to represent self contained unit of functionalities called service. SOA promotes design principles involving loose coupling, reusablility and coarse grained services. In Enterprise Architecture terms SOA benefits by delivering agility and reacting quickly to business needs, boosting return on investments by lowering the integration costs, reducing development cost by reusing components. The Enterprise Aarchitect’s promote the use of Enterprise Service Bus as an integration layer for large scale enterprise online applications.
E.g. A very good example will be Account Statement of your transactions, Product pricing information, image processing service, Map service, location service etc.
What are Webservices?
Web Services are just a form of implementation of service oriented architecture which can communicate between disparate systems in a platform independent manner.The service providers define an interface described by the WSDL and messages are exchanged with the service consumers using SOAP messages. The messages can be transmitted over HTTP, FTP or SMTP protocols.
Webservices can be of SOAP based or REST.
In today’s step by step guide we will explore how to create a SOAP based web service and a consumer which will consume the web service. We will use JAX-WS(Java API for XML Web Services) API for creating the web service.

Software:
Weblogic Application Server 12c
Eclipse Oepe 12c
Weblogic Webservice Tool – This will automatically create all the required code and WSDL files and let the developers focus on the business logic.
Step 1:
In your Eclipse create a new Dynamic Web Project.

Create New Dynamic Web Project

Create New Dynamic Web Project

Click modify and add the facets related to Weblogic Webservice components.

Step 2:
Click on the checkboxes to make sure all the dependent modules are also included as mentioned in the screenshot.

Add-Project Facets

Add Project Facets related to Weblogic Webservice

Step 3:
Default Context root is CalculatorServiceServer and content directory of the web module is WebContent. Click Finish.

Step 4:
Now right click on the newly created project and add Weblogic Web Service module to your project.

Create New  Webservice

Create New Weblogic Webservice

Step 5:
Create a new web service. Add the package details and give a name to the webservice.

Create New Web Service

Create New Web Service

Step 6:

The webservice tool in Eclipse will create the Service Endpoint interface (contract) with a default web method of hello(). We can replace the default method with the required method – add(). It is a best practice to create an interface that declares the methods which are mapped to the web service operations. This interface is known as Service Endpoint Interface (SEI). Whenever we see the annotation @WebService it denotes that the interface is a SEI.

Calcuator interface SEI

Calcuator interface SEI

Step 7:
CalculatorImpl.java is created as a JWS (Java Web Service) class.
Replace the default code present in the CalculatorImpl.java. Add the implementation details to the add().

Implementing SEI

Implementing SEI – CalculatorImpl.java

Step 8:
The below diagram explains the mapping between the webservice implementation annotated with @webService and the wsdl mapping.
Javax.jws.WebService tells to the application server that this class needs to be treated as a webservice. The various attributes of the javax.jws.Webservice are:

  • name – Name of the webservice and maps to <wsdl:portType> element in the WSDL file.
  • targetNameSpace – The XML namespace used for the WSDL and XML elements generated from this Web Service.
  • serviceName – serviceName of the web service. Default value is jws file name with the suffix of ‘service’.
  • wsdlLocation – URL of the absolute wsdl file.
  • endpointInterface – This is based on the exsisting webservice service endpoint’s (SEI).
JAX-WS & WSDL Comparision

JAX-WS & WSDL Comparision

In the above picture the webservice name in the Calculator interface is mapped to webservice name mentioned in the portType element in the WSDL.
The portName, serviceName, target Namespace and service end point interace (SEI) from CalculatorImpl.java is mapped to CalculatorService.wsdl file.

Step 9:
Now it’s time to run the webservice in the Weblogic 12c Server by right clicking the project and select Run on Sever and add the CalculatorServiceServer project to the Weblogic server and configure them.

Add CalculatorServiceServer project to the Weblogic server

Add CalculatorServiceServer project to the Weblogic server

Step 10:
The webservice is now deployed in the server and exposed to the clients for consuming. This can be accessed and controlled from the weblogic server console.

Weblogic Server Console

Weblogic Server Console

The wsdl file can be viewed and tested from the location as shown in the screenshot.

Step 11:
The wsdl file with the remote location address.

CalculatorService WSDL

CalculatorService WSDL

http://10.0.2.15:7001/CalculatorServiceServer/CalculatorServer?WSDL

Step 12:
The below diagram shows CalculatorService.wsdl file and explains all the key elements of the WSDL file. WSDLs are service contract with the clients and service providers.
Definition – The outermost element of the WSDL file is the <definitions>. This is the container for all other elements defined in the wsdl document. In summary this is the root element.

  • <types> – describes all the datatypes used and relevant for the message exchange between client and server. It is an optional field. The types section refers to the XSD (XML schema definition) which defines the data types. If this section is empty then only simple data types will be used by the web service.
  • <messages> – defines the data being exchanged between the provider and consumer of the webservice. Messages are created from the data types.
  • <portType> – represents the web service as named operations. Each operation can have one or more messages.
  • <binding> – defines how messages are transmitted. It is available over HTTP GET, HTTP POST, SOAP (on top of HTTP protocol). From the binding section the WSDL definitions go from abstract to concrete providing concrete details about the web service. The binding element must specify the implementation details of the webservice defined abstractly in the portType.
  • <service> – specifies on the endpoint, clients can access the web service from this path.
CalculatorService WSDL Explained

CalculatorService WSDL Explained

Step 13:
We can test the webservice with the help of Weblogic Test client.

WebLogic Test Client

WebLogic Test Client

Step 14:

Weblogic test client shows successful result of the add operation and gives the request and response SOAP message.

Test Client -SOAP Request & Response

Test Client -SOAP Request & Response

Step 15:

Now I want to create a servlet which will act as a webservice client which will consume the Calculator webservice which we have created in the previous steps.
Create a new Dynamic Web project – CalculatorServiceClient and add the facets Oracle Weblogic Web Service clients.

Add Weblogic Webservice Client facet

Add Weblogic Webservice Client facet

Step 16:

Create a new Web service client by right clicking the CalculatorServiceClient project -> Select New -> Select other -> Search Weblogic Web service client from the wizards. Now enter the reference to the WSDL file. In this case we will use the remote definition of the WSDL file. Before clicking please ensure to validate the WSDL file.

 

Add the WSDL location

Add the WSDL location

On click of next the CalculatorServiceServer codes are exported in the CalculatorService.jar. On clicking next specify the location of the Runtime WSDL location. I have used Copy WSDL into client jar option.

Create CalculatorService.jar

Create CalculatorService.jar

Step 17:

Now create a Servlet class which will invoke the Webservice.

Create Servlet to invoke Webservice

Create Servlet to invoke Webservice

Step 18:

Let’s look at the client Servlet code.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CalculatorService service = new CalculatorService();
		Calculator addservice = service.getCalculatorPort();
		int sum = addservice.add(1, 6);
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<h1> SUM=" + sum + "</h1>");		
		System.out.println("result sum-" + sum);
}

The output of the servlet displays all the result of the add operation.

TestCalculatorWS  servlet Output

TestCalculatorWS servlet Output

I hope you have enjoyed the article. Please post your review comments and feedback and share the knowledge using the social media buttons.

 Download the complete code:

Download Sample Code

Java Security Tutorial – Step by Step guide to create SSL connection and certificates

Step by StepIn our series of articles on applying JEE security we present you another detailed tutorial on how to create a SSL connection and create certificates in a Java EE application.
As mentioned in our previous article Secured Socket Layer (SSL)/ Transport Layer Security (TLS) will enable a secured connection between the client and the web server. The client will use HTTPS connection to use the web resources.
Java provides various security based APIs which can help to create a secured connection with the client and sending / receiving messages in an encrypted format:

  • Java Cryptography Architecture(JCA)
  • Java Cryptographic Extension(JCE)
  • Java Secured Socket Extension (JSSE)

To enable a SSL connection the web server needs to have a Digital Certificate which will allow clients to trust the authenticity of the web application. The application which wants to send an encrypted message applies for a Digital Certificate from the Certificate Authority (CA). The CA validates the application owner details and other identification details and issues a digital certificate.
In Public Key Infrastructure (PKI) scheme a digital certificate is issued by a CA and it contains Distinguished Name(DN) /owner’s name/ subject, a serial number to uniquely identify the certificate, owner’s public key, issuing date, expiry date, Distinguished name of the CA, digital signature of the issuing authority (CA), signature algorithm which is used to create the signature. Digital certificates issued by the CA can be kept in registries so that the authenticating users can use the owner’s public key.

How does browsers recognizes the authenticity of the application or website using the certificates?
All commercial CA have relationship with the major web browsers so that their root certificates are embedded in their browsers. The browser’s SSL compatibility can be checked through the certificate store which provides the information about the CA certificates which are stored in the browser’s store. Alternatively the CA websites also provide the information about the browser’s SSL compatibility.

The below image shows the certificate details for a sample website http://abcgen.uk. The below certificate assures the client that the authenticity of the owner has been verified and digital certificate has been issued to ABCGen Idiotechie plc with a Common Name as www.abcgen.uk.

Note: For security reasons we have not used any reference to a live website. The example used in this article is for illustrative and learning purposes only.
This example shows that the certificate is issued by Verisign as Class 3 which denotes that Verisign has performed an independent verification and validation of the owner. This is not a specified PKI standard.
The next field denotes the validity of this certificates.
The fingerprints denotes the public key but in an encoded format. The data is hashed using a cryptographic hash function SHA1 and MD5.

Sample Certificate Details in Mozilla

Sample Certificate Details

The below diagram displays the Certificate Hierarchy. The first item denotes the Root certificate and the second one displays the extended validation. The certificate authorities (CA) provide higher security certificates known as Extended validation.
All the major web browser’s key store will contain the information about the root and extended validation which will enable them to authenticate a particular application’s authenticity.

Certificate Hierarchy

Certificate Hierarchy

Hope everybody got the concept. Now let’s try some coding.

Products used:

  • IDE: Netbeans 7.2
  • Java Development Kit (JDK): Version 6
  • Glassfish server: 3.1
  • Authentication Mechanism: Form Based authentication
  • Authentication server: LDAP OpenDS v2.2

Objective:
Create a SSL connection between web server and the client.

Step 1:
Create a Server certificate in Glassfish server
Open a command prompt in windows -> Go to the {domain_dir}/config directory where {domain_dir} denotes the Glassfish domain path.
e.g. C:\NetBeans\7.2\config\GF3\domain1\config>

Step 2:
We will use keytool command to generate the certificates. Keytool is a key and certificate management utility provided by Java SE 6.
Run the keytool command as follows:
>keytool -genkey -alias server-alias -keyalg RSA -keypass changeit -storepass changeit -ke
ystore keystore.jks
The command will ask for the following details:
What is your first and last name?
[Unknown]:  localhost  <<For testing purposes we need to use localhost since it maps to the application server hostname. Ideally in production environments this field should include application server’s name.>>
What is the name of your organizational unit?
[Unknown]:  idiotechie
What is the name of your organization?
[Unknown]:  idiotechie
What is the name of your City or Locality?
[Unknown]:  edinburgh
What is the name of your State or Province?
[Unknown]:  EDN
What is the two-letter country code for this unit?
[Unknown]:  GB
Is CN=localhost, OU=idiotechie, O=idiotechie, L=edinburgh, ST=EDN, C=GB correct?
[no]:  YES
Step 3:
Export the generated certificate to server.cer file.
>keytool -export -alias server-alias -storepass changeit -file server.cer -keystore keysto
re.jks
Certificate stored in file <server.cer>
Step 4:
Add the certificate to the trust store file
>keytool -import -v -trustcacerts -alias server-alias -file server.cer -keystore cacerts.j
ks -keypass changeit -storepass changeit
Owner: CN=localhost, OU=idiotechie, O=idiotechie, L=edinburgh, ST=EDN, C=GB
Issuer: CN=localhost, OU=idiotechie, O=idiotechie, L=edinburgh, ST=EDN, C=GB
Serial number: 519e7165
Valid from: Thu May 23 20:43:33 BST 2013 until: Wed Aug 21 20:43:33 BST 2013
Certificate fingerprints:
MD5:  34:B7:71:CD:C9:56:9A:EA:0C:F2:91:50:EA:7F:4B:64
SHA1: AA:DE:EC:1B:27:8E:BC:3A:7A:82:8C:B7:FA:C3:AA:11:2F:97:1F:2C
Signature algorithm name: SHA1withRSA
Version: 3
Trust this certificate? [no]:  YES
Certificate was added to keystore
[Storing cacerts.jks]
Step 5:  Verify if the certificate was successfully added into the keystore.
>keytool -list -v -keystore keystore.jks
Enter keystore password:
Alias name: server-alias
Creation date: 23-May-2013
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=localhost, OU=idiotechie, O=idiotechie, L=edinburgh, ST=EDN, C=GB
Issuer: CN=localhost, OU=idiotechie, O=idiotechie, L=edinburgh, ST=EDN, C=GB
Serial number: 519e7165
Valid from: Thu May 23 20:43:33 BST 2013 until: Wed Aug 21 20:43:33 BST 2013
Certificate fingerprints:
MD5:  34:B7:71:CD:C9:56:9A:EA:0C:F2:91:50:EA:7F:4B:64
SHA1: AA:DE:EC:1B:27:8E:BC:3A:7A:82:8C:B7:FA:C3:AA:11:2F:97:1F:2C
Signature algorithm name: SHA1withRSA
Version: 3
Step 6: Validate if the certificate was successfully added into the trust store.
>keytool -list -keystore cacerts.jks
Enter keystore password:

server-alias, 23-May-2013, trustedCertEntry,
Certificate fingerprint (MD5): 34:B7:71:CD:C9:56:9A:EA:0C:F2:91:50:EA:7F:4B:64

So now the certificate is available both in the keystore and truststore. The keystore contains the private key of the server while truststore contains the CA certificates or the public keys only. This is a cleaner demarcation of the certificates and the keys where private keys can be kept in more secured environment in the keystores but public keys can be kept in more accessible option in the truststore.
However in this example since we do not have a CA certificate the server certificate is stored in the trusted store.

Step 7:
From the server configuration perspective let’s go to the server admin console.
Then click Configurations -> server-config->HTTP Service ->http-listeners-2.
Http-Listeners-2 denotes the secured HTTPS port 8181.
Click the SSL tab and modify the Certificate Nick-name to “server-alias” as per the certificate we have created above.

Application Server SSL settings

Application Server SSL settings

Step 8:
Restart the server.

So all the server related configurations are now done.

Let’s move into the application code.
We will use the same application code used for http://idiotechie.com/secure-web-application-in-java-ee6-using-ldap/.

The only change required is in web.xml where the transport-guarantee will be changed from none to confidential.

<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>

The CONFIDENTIAL protection mode is used when the application wants to prevent others entities to view the contents of the transmission.

Build, deploy and run the application.

Now even if you try to type the URL http://localhost:9999/SampleWebApp/index.jsp the server will redirect the users to the secured HTTPS connection through https://localhost:8181/SampleWebApp/index.jsp. Since the certificate produced by the server is self signed one instead of a certificate from CA the browsers gives a warning message notifying that the website’s security certificate cannot be trusted. This is due to the fact that browser’s truststore does not contain these certificates.

Secured Application

Secured Application

We can add the certificate in browser’s exception list to avoid future warnings. Let’s now try to check the certificate details of the sample application from the Mozilla Firefox browser:

Localhost Cerificate Details

Localhost Certificate Details

Hope my readers were able to understand how to create digital certificate and secure a web application. If you like this article please share this in the social networking sites and help us grow.

 Download Sample Code below:

Download Sample Code

Secure Web Application in Java EE6 using LDAP

In our previous article we have explained on how to protect the data while it is in transit through Transport Layer Security (TLS)/Secured Socket Layer (SSL). Now let us try to understand how to apply security mechanism for a JEE 6 based web application using LDAP server for authentication.

Objective:
•    Configure a LDAP realm in the JEE Application Server
•    Apply JEE security to a sample web application.

Products used:
IDE: Netbeans 7.2
Java Development Kit (JDK): Version 6
Glassfish server: 3.1
Authentication Mechanism: Form Based authentication
Authentication server: LDAP OpenDS v2.2

Apply JEE security to the sample web application:
The JEE web applications can be secured either through Declarative security or Programmatic security.
Declarative security can be implemented in JEE applications by using annotations or through deployment descriptor. This type of security mechanism is used when the roles and authentication process is simple, when it can make use of existing security providers (even external like LDAP, Kerberos).
Programmatic security provides additional security mechanism when declarative security is not sufficient for the application in context. It is used when we require custom made security and when rich set of roles, authentication is required.

Configure Realm in the Glassfish Application Server
Before we configure a realm in the Glassfish Application server you will need to install and configure an LDAP server which we will be using for our project. You can get the complete instructions in the following article: “How to install and configure LDAP server”.
Once the installation is successful start your Glassfish server and go to the admin console. Create a new LDAP Realm.

Create new LDAP Realm

Create new LDAP Realm

Add the configuration settings as per the configurations set up done for the LDAP server.

Glassfish Web App LDAP Realm

Glassfish Web App LDAP Realm

JAAS Context – identifier which will be used in the application module to connect with the LDAP server. (e.g. ldapRealm)
Directory – LDAP server URL path (e.g. ldap://localhost:389)
Base DN: Distinguished name in the LDAP directory identifying the location of the user data.
Applying JEE security to the web application
Create a sample web application as per the following structure:

SampleWebApp Directory

SampleWebApp Directory

Form based authentication mechanism will be used for authentication of the users.

JEE Login and Authentication

JEE Login and Authentication

Let us explain the whole process with help of above diagram and the code.

Set up a sample web application in Netbeans IDE.

SampleWebApp in Netbeans IDE

SampleWebApp in Netbeans IDE

SampleWebApp Configuration

SampleWebApp Configuration

Step 1:
As explained in the above diagram a client browser tries to request for a protected resource from the website http://{samplewebsite.com}/{contextroot}/index.jsp. The webserver goes into the web configuration file and figures out that the requested resource is protected.

web.xml

<security-constraint>
        <display-name>SecurityConstraint</display-name>
        <web-resource-collection>
            <web-resource-name>Secured resources</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>GeneralUser</role-name>
            <role-name>Administrator</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
</security-constraint>

Step 2:
The webserver presents the Login.jsp as a part of the Form based authentication mechanism to the client. These configurations are checked from the web configuration file.

web.xml

 <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>ldapRealm</realm-name>
        <form-login-config>
            <form-login-page>/Login.jsp</form-login-page>
            <form-error-page>/LoginError.jsp</form-error-page>
        </form-login-config>
</login-config>

Step 3:
The client submits the login form to the web server. When the servers finds that the form action is “j_security_check” it processes the request to authenticate the client’s credential. The jsp form must contain the login elements j_username and j_password which will allow the web server to invoke the login authentication mechanism.

Login.jsp

<form action="j_security_check" method=post>
            <p>username: <input type="text" name="j_username"></p>
            <p>password: <input type="password" name="j_password"></p>
            <input type="submit" value="submit">
            <input type="reset" value="Reset"> 
</form>

While processing the request the webserver will send the authentication request to the LDAP server since LDAP realm is used in the login-config.
The LDAP server will authenticate the user based on the username and password stored in the LDAP repository.

Step 4:
If the authentication is successful the secured resource (in this case index.jsp) is returned to the client and the container uses a session id to identify a login session for the client. The container maintains the login session with a cookie containing the session-id. The server sends this cookie back to the client, and as long as the client is able to show this cookie for subsequent requests, then the container easily recognize the client and hence maintains the session for this client.

Step 5:
Only if the authentication is unsuccessful the user will be redirected to the LoginError.jsp as per the configuration in the web.xml.

<form-error-page>/LoginError.jsp</form-error-page>

This shows how to apply form based security authentication to a sample web application. Now let us get a brief look on the secured resource which is used for this project.
In this project the secured resource is index.jsp which accepts a username and forwards the request to LoginServlet. Login servlet dispatches the request to Success.jsp which then prints the username to the client.

 index.jsp

 <body>
        <h2>Please type your name</h2>
        <form method="POST" action="LoginServlet">
            <input type="text" name="username" size="25">
            <p></p>
            <input type="submit" value="Submit">
            <input type="reset" value="Reset">
        </form>
 </body>

LoginServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            RequestDispatcher requestDispatcher = getServletConfig().getServletContext().
                    getRequestDispatcher("/Success.jsp");
            requestDispatcher.forward(request, response);
        } finally {
            out.close();
        }
    }

Success.jsp

<body>
        <h1>You have been successfully logged in as ${param.username}</h1>
</body>

Web.xml

<servlet>
        <servlet-name>LoginServlet</servlet-name>
        <servlet-class>com.login.LoginServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>LoginServlet</servlet-name>
        <url-pattern>/LoginServlet</url-pattern>
 </servlet-mapping>

You can download the complete working code from the below link.

SampleWebApp-Code Download

Hope our readers have enjoyed this article. Keep watching this space for more articles on JEE security.

How to install and configure LDAP server?

Step by StepWhat is LDAP?
“LDAP stands for Lightweight Directory Access Protocol used for accessing and maintaining distributed directory information services over an Internet Protocol network.”

Why is LDAP used?
LDAP is used for accessing a directory which can consist of a set of objects, users, groups, login, passwords, permissions etc. Its practical use is more in terms of authentication and access control mechanism. LDAP also provides add, delete, search, modify operations. LDAP is not considered as a standard relational database.
LDAP stores the attribute based data and they are generally read specific data. The entries in LDAP are maintained in tree like structure Directory Information Tree (DIT).

OpenDS is simple Java based open source directory service software which implements LDAP. In today’s series we will explore this product for demonstration of the LDAP server.
Let’s try to do a hands on exercise on how to install and configure OpenDS.
Step 1:
OpenDS software can be downloaded from https://opends.java.net/ link the OpenDS2.2 version.
Install OpenDS2.2 by clicking “setup.bat”.
Step 2:
Click the option “Install new server instance”.
Step 3:
Under Server Settings option Add the Host name matches the host name mentioned the config file of your application server. In this case we will use “localhost”. Fill up rest of the details along with the password.

 

Opends Server Settings

OpenDS Server Settings

Step 4:
In case of Topology option select this as a Standalone server.
Step 5:
Leave the default options of Directory base DN to dc=example, dc=com
Step 6:
Review and Finish
Step 7:
Launch Control Panel.
You can launch the control panel from the Finish Wizard or you can go to directory OpenDS\bat and execute the command control-panel.bat.
Step 8:
The control-panel.bat will open the Directory server control panel.

OpenDS Control Panel

OpenDS Control Panel

Step 9:
Add users – To add users in the LDAP directory click on Manage Entries option.

 

Manage Entries Panel

Manage Entries Panel

Step 10:
Right click on the dc=example, dc=com to add New User

Step 11:
In the New User panel add the details of the new user.
In this case the common name is admin.

New User Panel

New User Panel

We can also create a new group by using the New Group option and assign the created users to this group.

 

New Group

New Group

Terminologies:
dn – Each entry in the LDAP will have an unique identifier or distinguished name (DN).
cn – Common Name
sn – Surname
dc – Domain Component
ou – Organisational Unit
o – Organisation
st – State
l – Location
c – Country

LDAP Tree structure

LDAP Tree structure

We can also try various other LDAP servers available in the market including Active Directory (Microsoft), Apache Directory Server, IBM Tivoli Directory Server, OpenDJ, OpenLDAP among others.

In our next series we will try to explore how to use the LDAP server from JEE applications and apply security features in JEE based web application. Keep watching this space.

 

How to use cmd prompt inside Eclipse?

Quick tip As a part of our Quick Tips series we will show in this article how to use command prompt from inside Eclipse tool.There are times when we need to use the Windows command prompt for executing standalone Java programs. On the other hand you need to also use the eclipse for doing the development. So frustrating to switch isn’t it. Well, Eclipse tool actually gives us that option to use the windows command prompt inside Eclipse.

Step 1:  Setup a new External Configuration Tool

In the Eclipse tool go to Run -> External Tools -> External Tools Configurations option.

Step1 External Tool Option

Step1 External Tool Option in Eclipse

Step 2: Click New Launch Configuration option in Create, manage and run configuration screen

Step2 New Configuration Option

Step2 New Configuration Option

Step 3: New Configuration screen for configuring the command prompt

Step3 New Configuration Launched

Step3 New Configuration Launched

Step 4: Provide configuration details of the Command Prompt in the Main tab

  • Name: <<Give any name to your configuration (Here it is Command_Prompt)
  • Location: <<Location of the CMD.exe in your Windows>>
  • Working Directory: <<Any directory where you want to point the Command prompt>>

Step4 Configure CMD Location

Step4 Configure CMD Location

Step 5: Tick the check box Allocate console
This will ensure the eclipse console is being used as the command prompt for any input or output.

Step5 Allocate Console

Step5 Allocate Console

Step 6: Click Run and you are there!! You will land up in the C: directory as a working directory

Step6 Command Prompt with default working directory

Step6 Command Prompt with default working directory

Step 7: Sample commands in the Eclipse console.

Step7 Run CMD Commands

Step7 Run CMD Commands

That’s it. Please provide your feedback and comment if this tip is useful for you.