- Start Eclipse
- First Go to the package explorer and Right Click on your project and select PMD | Find Suspect Cut And Paste
- PMD creates a folder reports under your project and stores the result text file
- Select Window | Show View | Navigator
- In Navigator view click on Your Project and then on the reports folder
- The report file cpd-report.txt should look like this:
Found a 5 line (15 tokens) duplication in the following files:
Starting at line 21 of G:\besthowtodo\workspace\HelloDynaWeb\src\com\besthowtodo\tutorials\dynaweb\DemoPMDThread.java
Starting at line 25 of G:\besthowtodo\workspace\HelloDynaWeb\src\com\besthowtodo\tutorials\dynaweb\DemoPMDThread.java
public void WRITE_SOMETHING_WITH_COPY_PASTE(String INPUT_PARAMETER) {
System.out.println(INPUT_PARAMETER);
}
public static void main(String[] args) {
Saturday, May 8, 2010
How to find Cut and Paste Code in Eclipse Using PMD ?
How to Generating PMD Reports InEclipse ?
- Right Click on the java project in the project explorer and select PMD | Generate reports
- It creates a report folder in your application and create violation report.
- Select Window | Show View | Navigator
- In Navigator view click on Project and then on the reports folder
- That folder content same report in different format one of them html format. It is something like:
Wednesday, May 5, 2010
How to use PMD in Eclipse ?
- Launch Eclipse
- Let you have previously created a Java Project PMDDemo, Otherwise you need to create a new project in your workspace File | New | Project...
- In the Package Explorer right-click on PMDDemo project and select New | Class
- In the following dialog enter the class name as DemoPMD and click Finish
- A new class DemoPMD is created in project's default package. Paste the following code into the new class:
public class DemoOMD {
private static final String bAD = "BAD";
public void BadMethodName() {
System.out.println("Hello PMD World!");
}
public String thisIsCutAndPaste(String first, int second) {
System.out.println("New world");
return "New world";
}
} - Similarly, create a second class DemoPMDThread and paste the following code:
public class DemoPMDThread extends Thread {
public DemoPMDThread(String str) {
super(str);
}
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println(i + " " + getName());
try {
sleep((long) (Math.random() * 1000));
} catch (InterruptedException e) {
}
}
System.out.println("DONE! " + getName());
}
public void WRITE_SOMETHING(String INPUT_PARAMETER) {
System.out.println(INPUT_PARAMETER);
}
public static void main(String[] args) {
new Yang("Good").start();
new Yang("Bad").start();
}
public String thisIsCutAndPaste(String pFirst, int pSecond) {
System.out.println("New world");
return "New world";
}
}
7. In the Package Explorer right-click on QA Project and select PMD | Check Code With PMD
If PMD Violations view is not open navigate to Window | Show View | Other... and select PMD | PMD Violations, you'll get following view...
In the PMD Violations view notice a list of 27 violations. In large projects this list could easily grow up to several thousand. This is one of the reasons PMD allows violations be filtered by priority. Priority is a configurable attribute of a PMD rule. PMD assigns priorities from 1 to 5 and each priority is represented by a colored square at the top-right corner of the view. These little squares are actually clickable on-off switches used to control the visibility of the violations they represent.
The results table itself is well laid out and most columns are sortable. It is also possible to get more detail on a violation by simply right-clicking it and selecting Show Details. PMD pops-up a dialog with information such as rule name, implementation class, message, description and an example. This feature can be helpful when trying to makes sense of a new rule or letting inhouse developers know about a particular company rule or coding convention.
How to install PMD in Eclipse ?
The easiest way to install PMD is by using the remote update site.
Users behind firewalls should check proxy settings before going any further.
If these settings are misconfigured the updater will not work. PMD also
supplies a zip file for manual installation. Download the file and follow
the readme. Demonstrated below is installing PMD via the Eclipse Software Updater.
- Launch Eclipse.
- Navigate to Help | Software Updates | Find and Install...
- Select "Search for new features to install" and click Next
- Click New Remote Site...
- Enter a name (PMD) and the URL http://pmd.sourceforge.net/eclipse
- In Sites to include in search check PMD and click Finish
- In the Search Results dialog check PMD for Eclipse 3 3.1.0 and click Next
- Accept the terms of the license agreements and click Next
- Click Finish.
- Wait for Eclipse to download the required jar files, then click Install
- Restart the workbench. This will load the PMD plugin.
- Navigate to Window | Show View | Other...
- Select PMD | PMD Violations
- PMD Violations view should appear at the bottom pane
Sunday, May 2, 2010
How do I make my web application be the Tomcat default application ?
Then before you replace the current default application, it may be a good idea to make a copy of it somewhere else.
Then delete everything under the ROOT directory, and move everything that was previously under the (CATALINA_BASE)/webapps/besthowtodo/ directory, toward this (CATALINA_BASE)/webapps/ROOT directory. In other words, what was previously .../besthowtodo/WEB-INF should now be .../ROOT/WEB-INF (and not .../ROOT/besthowtodo/WEB-INF).
<servlet> <servlet-name>Best HowToDO Servlet</servlet-name> <servlet-class>com.besthowtodo.tutorials.Servlet.Number1</servlet-class> </servlet> <servlet-mapping> <servlet-name>Best HowToDO Servlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
Call up "http://besthowtodo.company.com/" and enjoy.
- delete the ROOT directory
- name your war file "ROOT.war" (capitals mandatory)
- drop the ROOT.war file directly in the /webapps directory.
Tomcat will automatically deploy it.
how do I set memory related settings to improve Tomcat performance?
When our web application is using large memory as this memory size default setting can be too small, 64MB by default,thus the application becomes slower because the garbage collector is invoked more often, and it can even run out of memory (outofmemory / heap space error ). One way to address this problem is to set a larger heap size . In Windows system, this can be done by editing / adding JAVA_OPTS variable (should be early in the file) in CATALINA_HOME/bin/catalina.bat or catalina.sh for Linux/Unix systems.Parameters to be added are , let say you want to increase it to 256 MB (as you required but make sure you have enough amount of physical memory/RAM and for 32bit system , use no more than 1-1.1 GB heap space size ) , use '-Xms256m -Xmx256m' .In some cases , it is better to set slightly lower size for -Xms . There are other parameters can be added , some of them :'-XX:MaxNewSize -XX:NewSize -XX:MaxPermSize' , depending on your application and requirements .
For catalina.bat there now should be a line in the file that looks like this: set JAVA_OPTS=-Xms256m -Xmx256m
For catalina.sh: JAVA_OPTS='-Xms256m -Xmx256m'
For other parameters , Try this Apache Link:
http://wiki.apache.org/tomcat/FAQ/Memory
http://wiki.apache.org/tomcat/OutOfMemory
How do I share sessions across web apps?
How to set the SDK JRE as the default JRE for Eclipse ?
Figure 1. Eclipse preferences
Select the Java option from the left-hand tree view. Expand the Java element and select Installed JRE's, as shown in Figure 2.
Figure 2. JRE preference settings
Click Add and navigate to the JRE directory of the SDK you installed during the installation phase of the configuration above, as shown in Figure 3. Click OK.
Figure 3. Adding a JRE to the Eclipse preference settings
Check the check box beside the JRE you just added from the SDK you installed, as shown in Figure 4. This sets this JRE as the default JRE to be used by Eclipse.
Figure 4. Setting the default JRE for Eclipse
Just Select OK, now we have configured JDK with Eclipse default JRE
How to add meta keyword and description in blogspot ?
To do this use following steps
Step 1: Login to the Blogger site
Step 2: Go to the Layout tab
Step 3: Then clicks on the Edit HTML tab
Step 4: Now Search for the following lines
<b:include data='blog' name='all-head-content'/>
Step 5: Now Add the following META TAG information just below the above tag
<meta content='THIS IS THE DESCRIPTION OF YOUR BLOG' name='description'/>
<meta content='LIST OF KEYWORD FOR YOUR BLOG' name='keywords'/>
<meta content='AUTHOR' name='author'/>
Step 6: Save the layout, You can now check your blogs HTML source code to verify it
How to create dynamic web project in Eclipse ?
- First select the File menu and then "Dynamic Web Project". If there is no "Dynamic Web Project" then choose "Others..." option
2) If you selected "Other..." then you'll get following screen. Find the "web" folder and then expend it and select "Dynamic Web Project" and click on the "Next" button.
3) Then Write the project name and select runtime server(If you don't know how to configure tomcat with Eclipse, then follow this article "How to configure Tomcat with Eclipse ?"). I have selected tomcat.
4) After above steps you'll get following screen. Context root is your default application name, Content directory is the location in which you need to place all your JSP, Java script files....... and last one is src folder. It is the name of source folder. You can rename it with any other words but for now I am going to use default one.
5) After click on Next button you'll get a new entry for project in the "Project Explorer".
6) Below is the folder structure of a new web application. Eclipse creates all required folder structure for your project.
How to configure Tomcat with Eclipse ?
Eclipse 3.4
Tomcat 6.0.x
Step1: First download the tomcat and install it any location of your hard drive.
Step2: Run the eclipse (If already not installed go the link "how to install Eclipse"). Clicks on the window menu and then Preferences menu item
Then you'll get...
Step 3: Now expend the server item and select Runtime environment and after that click on the add button.
After clicking on the add button you'll get following screen......
Step 4: Now select Apache as a server type and expend and select tomcat 6.0(choose according to the tomcat version you are using ). I am using tomcat 6.0.x so I selected tomcat 6.0 and then clicks on the next button.
After that you'll get following screen.......
Step 5:Clicks on the browse button
Step 6: Now find the location of tomcat on your local drive and select tomcat folder and clicks on the OK button
Step 7: Now the final view something like this, and clicks on the Finish button.
After that you'll get following screen
Step 8: After above step, you have configured tomcat with Eclipse and can use it with eclipse. Now clicks on the OK button
Step 9: Now we need to view our tomcat server in eclipse so first click on the window menu and select Show View and then other view.
After that you'll get following screen.......
Step 10: Now select Server item and then select server
Step 12: Now right click on the server view as shown in the following figure. Again select new and thne Server and click
After that you'll get following screen.
Step 13:Again select Apache and then tomcat 6.0 and clicks on the next button
Step 14: Following screen'll show you all application that are present in the tomcat workspace and ready to run on tomcat server. Right panel content all application that are ready to run on tomcat server.
And click on the finish button.
After that in the server view you get tomcat server is ready to run.
Step 15: There are 2 main buttons that are used to run tomcat according to developer needs. If you want to run tomcat in debug mode then select left button otherwise use right button.
Step 16:Let you have clicked on the right button then you'll see following status(started) and if you like to see the server log then click on the console view.
Step 17:If there is no error message in the console view and get some server startup time that means you have perfectly configure tomcat with Eclipse and able to use it.
How to install Eclipse ?
1) Java 1.5+
2) Eclipse
Prearrangement : Considered that you have already installed Java 1.5+
Step 1: Go to the http://www.eclipse.org and click on the download link.
Step 2: You'll get Download page according to the your requirement, select Eclipse down loadable file. Now I am going to download Eclipse J2EE version.
Step 3: Click on the download Button
Step 4: Save file in your local drive.
Step 5: You can save and unzip it at any location of your local disc. Let you have saved it in "G:\besthowtodo". Then Eclipse location will be "G:\besthowtodo\eclipse". You need to also create a new folder for workspace that content all created projects.
Step 6:Now double click on the eclipse.exe file and then you'll get ...
Step 7: Now browse the your workspace and click on the OK button
Step 8: After that you'll get WelCome page of Eclipse
Step 9: Now Eclipse is ready for you .......... :)