Posted in Java

How to Remove Unbound classpath container / Build Path Entry Missing Error in Eclipse?


Build Path Entry Missing Error in Eclipse

How to Remove Unbound classpath container:  Build Path Problem or Build Path Entry Missing Error?

Java – Download Free EBooks and Whitepapers

Unbound classpath container Error in Eclipse

You might have set Execution environment i.e. JRE7 in Project for compilation but JRE7 is not added in the Eclipse.

Solution -> How to install and add JRE7 in Eclipse?

Cloud Computing – Download Free EBooks and Whitepapers
Java – Download Free EBooks and Whitepapers
Windows – Download Free EBooks and Whitepapers
Advertisements
Posted in How To..., Java, JEE / J2EE / JSP / Servlets

How to remove Empty Packages from Package Explorer in Eclipse


remove Empty Packages from Package Explorer in Eclipse

Open Eclipse -> Go to Package Explorer View

Empty Packages in Project Explorer in Eclipse
Empty Packages in Project Explorer in Eclipse
Cloud Computing – Download Free EBooks and Whitepapers
Java – Download Free EBooks and Whitepapers
Windows – Download Free EBooks and Whitepapers

Select Filters

Filters for Packages in Eclipse
Filters for Packages in Eclipse

Java Element Filters in Eclipse…

Select the Empty Packages Element to From the View
Select the Empty Packages Element to From the View

Done!!!

Posted in Java, JEE / J2EE / JSP / Servlets, Tomcat, Windows

How to debug Web Application remotely with Eclipse Indigo and Tomcat 7.0.22?


Lets create and simple Web Application with Single Servlet.

Java – Download Free EBooks and Whitepapers

Visit How to Create and Run Web Project (Java) in Eclipse

Once the Web Application is ready, lets export .war file to Tomcat 7.0.22.

Visit How to Export WAR file from Eclipse to Tomcat

Now let’s verify whether debug property is set or not in catalina.bat file;

it is available at apache-tomcat-7.0.22bin; By default settings are done for debugging in Tomcat 7.0.22. If it is not done or modified then do the following changes.

catalina.bat in Tomcat
catalina.bat in Tomcat

Open the Servlet source file of the web application in Eclipse and set the BREAK point.

Breakpoint in Eclipse to debug web application remotely
Breakpoint in Eclipse to debug web application remotely

Select Debug Configurations

Now. Change the Debug Configurations.

Debug Configuration in Eclipse
Debug Configuration in Eclipse

Open command prompt -> Go to the path of Tomcat distribution Directory/bin

catalina jpda start

Start Tomcat in Debug Mode
Start Tomcat in Debug Mode

Click on Debug on Eclipse

Debug in Eclipse
Debug in Eclipse

Open the Browser and enter the URL (in our case it is http://localhost:8080/JavaWebProject/HelloWorldExample)

Run Web Application Firefox
Run Web Application Firefox

The moment you press enter, you will see debug mode indicator in taskbar,

Debug Mode
Debug Mode

Now the flow will be paused on the breakpoint we created earlier.

Remote debugging of an Application in Eclipse
Remote debugging of an Application in Eclipse

Now you can use Step Into (f5), Step Over (f6), Step Return (f7) to debug as per the application code and your requirement to debug, for simplicity we have only one statement for debugging.

Debug Buttons in Eclipse
Debug Buttons in Eclipse

Now in browser you will be able to see the output.

Servlet Output
Servlet Output

Other Interesting Tomcat related Articles:

Posted in How To..., Java, JEE / J2EE / JSP / Servlets, Tomcat

How to Export WAR file from Eclipse to Tomcat


To export WAR file from the Dynamic Web Project in Eclipse, Follow below steps:

Export WAR File
Export WAR File

Java – Download Free EBooks and Whitepapers

Now select the destination where you want to deploy the WAR file; in our case, it will be Tomcat‘s “webapps” directory.

Select Destination to Deploy WAR file
Select Destination to Deploy WAR file

If you want to maintain source files (.java) then click on export source files as well.

Select Destination to Deploy WAR file
Select Destination to Deploy WAR file

Now verify the webapps directory in Tomcat’s distribution folder.

webapps directory in Tomcat's distribution folder
webapps directory in Tomcat’s distribution folder

Lets run the Web Application and verify

Run Tomcat, and you will notice that the WAR file content will be extracted into the folder

Once tomcat is Up and Running, Open Browser and open the URL http://localhost:8080/JavaWebProject/HelloWorldExample, you will see

Successful Servlet Execution in Tomcat Server in Browser
Successful Servlet Execution in Tomcat Server in Browser

Done!!! 🙂

Other Interesting Tomcat related Articles:

Posted in How To..., Java, JEE / J2EE / JSP / Servlets

How to Solve Servlet Errors in Eclipse?


Servlet Errors in Eclipse

For new users, it’s common to encounter following errors while developing servlet in Eclipse (I am using eclipse-jee-indigo-SR2-win32) or without it:

HttpServlet cannot be resolved to a type
HttpServletRequest cannot be resolved to a type
HttpServletResponse cannot be resolved to a type
ServletException cannot be resolved to a type
The import javax.servlet cannot be resolved
WebServlet cannot be resolved to a type

servlet-api.jar errors in eclipse
servlet-api.jar errors in eclipse

Java – Download Free EBooks and Whitepapers

The problem is “servlet-api.jar” is not on classpath.

How to add servlet-api.jar in classpath from Eclipse?

Right Click on the Web Project and Click on Properties

Dynamic Web Project Properties in Eclipse
Dynamic Web Project Properties in Eclipse

Select Java Build Path

Java Build Path in Eclipse
Java Build Path in Eclipse

Click on the Library Tab

Java Build Path in Eclipse-Libraries
Java Build Path in Eclipse-Libraries

Click on “Add External Jar” -> Locate servlet-api.jar from your local system (It’s available in Tomcat Distribution directory.)

Add External Jar servlet-api.jar from tomcat installation dir
Add External Jar servlet-api.jar from tomcat installation dir
servlet-api.jar external jar added
servlet-api.jar external jar added

Click OK and all errors will be resolved.

Servlet errors resolved
Servlet errors resolved

Done!!!

Other Interesting Tomcat related Articles:

Posted in How To..., Java

How to Import Existing Java Project in Eclipse


Import Existing Java Project -> Open Eclipse -> Click on File Menu -> New -> Java Project
Java Project
Java Project

Java – Download Free EBooks and Whitepapers

Give Java Project Name

New Java Project
New Java Project
New Java Project Settings
New Java Project Settings

Click on Finish; New Java Project will be available in Project Explorer -> Right Click on it…

Import Existing Project
Import Existing Project
Select General -> File System
Select General -> File System

a

Select Existing Project from File System
Select Existing Project from File System
Overwrite Dialog Box
Overwrite Dialog Box

See the Red Cross Mark in added Project due to Jar files

Java Source File Errors
Java Source File Errors

Right Click on the Imported Project

configure build path in eclipse
configure build path in eclipse

Click on Add Jars;

Add Jars in Eclipse
Add Jars in Eclipse

If Jars are not available in the Same Project which is imported then click on Add External Jar in above dialog box, Select Jars from the directory available on your system.

Jar Selcetion
Jar Selcetion

Click on Ok.

Notice, Red Marks are Gone..

Source Files Errors Removed After adding Jars in Classpath
Source Files Errors Removed After adding Jars in Classpath
Posted in Ant, Java

How ANT works?


How ANT works?

Each Project will have a build file (build.xml)

Each build file will contain one or more Targets

Java – Download Free EBooks and Whitepapers

The Target to be executed:

                Is either explicitly selected on the command line

                Or a project default Target is executed

Java™ Application Development on Linux® – Free 599 Page eBook

Enterprise Java Virtualization:

Understanding the TCO Implications

InfoWorld’s Java IDE Comparison Strategy Guide:

Java Essential Training

Apache Jakarta Commons: Reusable Java™ Components

Enabling Rapid ROI: With Java™ – Based Business Intelligence Applications:

Each Target is executed only once.

Project

is the top level element in an Ant script

<project> has three optional attributes:

                name: the name of the project

                default: the default target to use when no target is supplied

                basedir: the base directory from which all path calculations are done

<project name=“MyProject” default=“compile”>

                <!–- properties and targets will come here…–>

</project>

Targets

             Each project defines zero or more targets

             A target is a set of tasks you want to be executed

             When starting Ant, you can select which target(s) you want to have executed

             When no target is given, the project’s default is used

             Targets can be conditionally executed (using if/unless)

             A target can depend on other targets

             Target dependencies are transitive

             Each Target will contain one or more Tasks

             Some Tasks are executed conditionally

             Tasks are implemented as Java classes

<project name=“MyProject” default=“compile”>

                <property name=”buildDir” value=”build”/>

                <property name=“srcDir” value=“.”/> 

                <target name=”compile”>

                                <!–Tasks will come here…–>

                </target>

</project>

Tasks

             A task is a piece of code that can be executed

             A task can have multiple attributes (a.k.a arguments)

             The value of an attribute might use the value of a property.

             Ant comes with over 80 core tasks, and 60 optional tasks

             Ant task extensions can be easily written for any unique problem

<project name=“MyProject” default=“compile”>

                <property name=”buildDir” value=”build”/>

                <property name=“srcDir” value=“.”/> 

                <target name=”compile”>

                                <javac srcdir=”${srcDir}”               destdir=”${build}”/>

                </target>

</project>

Single Sign-On for Java and Web Applications

Bulletproof Java Code: A Practical Strategy for Developing Functional, Reliable, and Secure Java Code

Transforming a Generic Java IDE to Your Application Specific IDE:

The Java Virtual Appliance—No OS Required

BEA WebLogic® Operations Control: Application Virtualization for Enterprise Java

Enabling Rapid ROI: With Java™ – Based Business Intelligence Applications: