Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Friday, August 26, 2022

Installing apache24 in eclipse (Not apache tomcat)

 Go to Run menu, select External Tools click and select External Tools configuration like below





After that click on Program and add new program and select the location of apache server



Monday, July 4, 2022

How to enable auto formatting in Eclipse

 After creating a custom code formatter in Eclipse, as discussed in my previous post How to create and share Eclipse code style formatter, it is now time to put that code formatter in action. Code formatting should be an automatic process. Following are the steps which describe how to enable auto formatting in Eclipse.

Step 1

Open Eclipse and go to Window -> Preferences

Go to Window - Preferences

Step 2

In Preferences window, go to Java -> Editor -> Save Actions

Go to Save Actions

Step 3

In the right pane of Save Actions, check the following options:

  • Perform the selected actions on save
  • Format the source code – Within this, select the radio button labelled, Format edited lines. This will prevent formatting the entire code when only a certain section of code is saved after being edited.
Enable options in save actions

Click on Apply and then OK to save the changes. Now the next time you hit save in Eclipse, your code will be automatically formatted. Pretty cool, eh?

How to attach JDK source code in Eclipse

 Often while debugging Java applications, it is required to view the source code of standard Java classes. This post describes how to attach JDK source code in Eclipse IDE.

Step 1

Open Eclipse and go to Window -> Preferences

Go to Window - Preferences

Step 2

In Preferences window, go to Java -> Installed JREs. Select the JRE and click on the Edit button.

Go to Preferences - Java - Installed JREs

In the Edit JRE window, select the file rt.jar in the section named JRE system libraries and click on Source Attachment button.

Edit JRE source location

In the Source Attachment Configuration window, provide the location of the src.zip which is usually found in the JDK root folder. For example, C:/Program Files/Java/jdk1.7.0_13/src.zip

Provide JDK source file location

Click OK -> Finish -> OK to save and apply the changes. Now in your Java program if you press CTRL + left-mouse-click on any standard Java class, for example java.lang.System, it will open up the source code for that class.

How to change user name in Eclipse code templates

 When a new code file is created, the author name in the @author is set to the value which is taken from the user.name environment variable. One way to override this value is to modify the eclipse.ini file. Following are the steps which will show you how to change user name in Eclipse code templates.

Navigate to the location of eclipse.ini file on your system (a file search will reveal its location). Add the following parameter to the list of the Virtual Machine arguments in the eclipse.ini file.

How to change user name in Eclipse code templates
eclipse.ini
-vmargs ... ... ... -Duser.name=Your name

Make sure to add this user name argument after the -vmargs command and also don't forget to restart Eclipse after making this change. After this change, wherever the ${user} variable is used, it will be replaced with the user name entered in the eclipse.ini file.

How to change user name in Eclipse code templates

How to install Java Decompiler for Eclipse

 Often there is a need to decompile third party or standard Java classes to understand their code. But there is no built-in Java decompiler for Eclipse. However there are freely available external plugins which can be installed in Eclipse to create a built-in decompilation option. Java Decompiler project is one such plugin. In this blog, I’ll list down the steps required to install the JD-Eclipse plugin.

Step 1 – Install JD-Eclipse plugin

Open Eclipse and go to the menu option Help -> Install New Software… In the Available Software window, click on the link, Available Software Sites. In the window, click on Add button. In the pop-up window, provide any name to the site and paste the update site URL as http://jd.benow.ca/jd-eclipse/update and click on OK.

Go to option Install New Software in Eclipse
Click on Available Software Sites
Click on Add to create a new software site
Add a new site for JD-Eclipse

In the Available Software window, select the newly created site from the drop down and wait. Eclipse will fetch the list of plugins available for installation.

Note
While updating Eclipse in a corporate network, a proxy authentication error might be thrown in case the proxy settings are not maintained in Eclipse. Please refer to my blog How to add proxy settings in Eclipse for solving proxy issues in Eclipse.

Proxy Authentication Error in Eclipse

Select all the packages and click Next. Accept the license agreement and click Finish to begin the installation of plugin.

Select the JD-Eclipse packages for downloading
Accept the license

Restart Eclipse after the installation is finished.

Restart Eclipse

Step 2 – Make JD-Eclipse as default class editor

In the Eclipse menu and go to Window -> Preferences

Go to Window - Preferences

In the Preferences windows, go to General -> Editors -> File Associations. In the right-pane, select .class without source as the file type. In the Associated editors: section below, click on the Add button. In the pop-up window which opens up, select Internal editors and in the list below it, select the Class File Editor and click on the OK button

Select the Class File Editor (identified by the coffee-cup icon) and click on the Default button. This makes JD-Eclipse as the default decompiler for class files without source.

Now, simply double-click on any .class file and JD-Eclipse will decompile it for you. You can also place debug points in the decompiled classes while debugging your applications.

Note
The JD-eclipse plugin can only decompile .class files that are visible from the classpath/build path.

How to install Python PyDev plugin in Eclipse (Manual installation, not from eclipse marketplace/url)

 Eclipse is a favourite tool for Java/JEE developers (including me ðŸ™‚ ). When I started learning Python, I wanted to use Eclipse as my preferred IDE for Python development. I found out that PyDev is one good open source plugin which can very well integrate with Eclipse.

Although PyDev is available through Eclipse Marketplace, I had some problems making it work from there. After a few hit and trials, I found a way to integrate the plugin in Eclipse without going through the marketplace. With this blog, I would like to share the steps for how to install Python PyDev plugin in Eclipse.

Prerequisites

1. Make sure that the latest version of the Java Development Kit is installed on your computer.
2. Download and install the Eclipse IDE for Java EE Developers for your operating system.

Installation Steps

Download the zip release of PyDev plugin.

Unzip the downloaded PyDev plugin. It will contain two folders; features and plugins

Browse to your Eclipse installation folder and locate the dropins folder

Copy the features and plugins from the unzipped PyDev plugin to the dropins folder

Restart Eclipse and open the PyDev perspective to verify that Pydev plugin has successfully installed

Now that the PyDev plugin is installed, let’s create a Python Hello World project to validate that our IDE is ready to crunch Python code. Open the project wizard and create a new Python project.

If Python is not installed on the system or Python interpreter is not configured, the project creation wizard will show an error “Project interpreter not specified”

If Python is not installed, this is just the right time to do so. Go to the Python website and download the appropriate installer.

After installing Python, go back to the project creation wizard and click on the link text “Please configure an interpreter before proceeding” and in the pop-up window, click on the button, Quick Auto-Config. This will automatically find the installation path of Python and configure Python interpreter in Eclipse.
While you are there, also click on the option, “Create ‘src’ folder and add it to the PYTHONPATH”

Create a package within the HelloWorld src folder and create a module which prints Hello PyDev! text.

Run the program and it should display Hello PyDev! on the console output

Hope that helps. In the next blog, I’ll show you how to install Python packages in Eclipse. See you in the next blog!

Thursday, April 19, 2018

Servlet session maintenance - to disable caching

                   // Set to expire far in the past.
  response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");

  // Set standard HTTP/1.1 no-cache headers.
  response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");

  // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
  response.addHeader("Cache-Control", "post-check=0, pre-check=0");

  // Set standard HTTP/1.0 no-cache header.
  response.setHeader("Pragma", "no-cache");

Monday, March 20, 2017

Jdbc configurations in eclipse

 Usage of Mariadb java connector


#Download mariadb java connector mariadb-java-client-1.3.6.jar (exact name depends on the driver version) from https://downloads.mariadb.org/connector-java/
#Then include in eclipse under java build path --> libraries --> Add External Jar files and also include in tomcat web server under lib folder
#In servlet use the below code

<pre>
  //loading drivers for mysql
            Class.forName("org.mariadb.jdbc.Driver");

//creating connection with the database
          Connection  con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","dbuser","dbpasswd");
</pre>

 Usage of mysqldb java connector 


#Download mysql java connector mysql-connector-java-5.1.36-bin.jar (exact name depends on the driver version) from http://www.mysql.com/downloads/connector/j/
#Then include in eclipse under java build path --> libraries --> Add External Jar files and also include in tomcat web server under lib folder
#In servlet use the below code

<pre>
            //loading drivers for mysql
            Class.forName("com.mysql.jdbc.Driver");
 

//creating connection with the database
          Connection  con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","dbuser","dbpasswd");
</pre>