Eclipse

Articles
Videos

Eclipse - VPN
Subclipse
Maven
Shortcuts
Tomcat

https://sewiki.iai.uni-bonn.de/research/pdt/docs/getting_started
Jetty

Out of memory problem with Eclipse or Ant
Dealing with projects that have circular dependencies

What is string_prompt?

StringPrompt is part of Eclipse. It cause Eclipse to display a prompt so that the user can enter value. This is handy when we have a .launch script / file. Essentially, if we want Eclipse to prompt us to enter a value, we would be using this. Add string_prompt as a Program Argument in the Run configuration:

${string_prompt}

There are also a file_prompt and a folder_prompt if you want specifically files\folders. These are available through the Variables button on the (x)= Arguments tab of the Run Configuration dialog.

We can also type:

${string_prompt:My Prompt Text:Default Value}

And that will pop up a window asking 'Please input a value for My Prompt Text' and then with a default value of 'Default Value'.

You can have only one prompt in which you can pass as many arguments as you want separated by spaces. The strings you provide with the prompt will be assigned to args variable of public static void main method of your class. To provide defaults for more than a argument, you could use something like this:

${string_prompt:"Enter two values separated by space":firstDefault secondDefault}

If you need to repeat your test many times with same parameters, you can think about using a saved run configuration in which you fix your parameters (just list them into "Program arguments" of "Arguments" tab).

You can use multiple string_prompt entries in your run configuration. This is what I'm currently using for a user/password combo in my Program arguments.

${string_prompt:Username:DefaultUsername} ${string_prompt:Password}

The first string_prompt shows a dialog box saying "Please input a value for Username", with the default value of DefaultUsername filled in. The second reads "Please input a value for Password" with no default value. Both arguments get passed in each time I run. Works great!

How did we use StringPrompt in our Tomcat launch script?

We created the serverName.launch file. This is used for starting Tomcat from inside Eclipse. One of the tag in this file is stringAttribute and it looks like:

<stringAttribute 
    key="org.eclipse.jdt.launching.VM_ARGUMENTS" 
    value="-Ddb_pw=${string_prompt:Please enter the database password for ...}"/>

This particular tag represents VM_ARGUMENTS and the value attribute for this tag contains a lot of -D flags. All these -D flags (VM arguments) are passed on to Tomcat, and inside the server.xml file we have:

<Context caseSensitive="false" docBase="rrm-war" path="/" reloadable="false" source="org.eclipse.jst.j2ee.server:rrm-war">
    <Resource 
        auth="Container" 
        connectionProperties="SetBigStringTryClob=true" 
        driverClassName="oracle.jdbc.OracleDriver" 
        maxActive="10" 
        maxIdle="3" 
        maxWait="10000" 
        name="Q...DataSource" 
        password="${db_pw}" 
        type="javax.sql.DataSource" 
        url="jdbc:oracle:thin:@FULL_HOSTNAME_OR_IP:PORT_NUMBER:SERVICE_NAME_OR_SID" 
        username="report"/>
</Context>

In the above code, inside our server.xml file, we access the VM argument db_pw.

How can we take advantage of multiple screens?

Eclipse allow us to take advantage of multiple screens. It also allows us to open the same file in multiple editor instances. Inside Project Explorer, find the file that we want to open, right click on it, and select "Open With", and select appropriate option. Once the file is opened, we can click on its tab and drag it to an un-used screen, and Eclipse will start to use that screen.

How can we import an existing project?

  1. If its already a Eclipse Project, then simply go to File->Import->General->Existing Project into Workplace.
  2. Otherwise define project type e.g. Java, Web etc Create a new project of type you define into your workplace. Copy Paste source , lib and other necessary files. refresh, compile and run project in eclipse.

How can we format code?

  1. CTRL+SHIFT+F (on Windows) or COMMAND+SHIFT+F (on Mac)

How can we quickly find files containing a string?

CTRL+ALT+F

This will open the Search dialog, but default to the File Search tab. We can type the text that we want to search for into the "Containing text" field, and click on the Search button.

How can we quickly find files with names containing a string?

CTRL+SHFT+R

How can we undock a view?

Just drag the view to the outside of your Eclipse window.

Does Eclipse support multiple clipboards?

Yes and No. By default, Eclipse does not seem to support multiple clipboards. However, there are Eclipse plugins that you can install. I use More Clipboard. Other solutions or plugins:

How can we create a new Java project:

File -> New -> Java Project

How can we create a new Java class for your project:

File -> New -> Class

How can we compile and run a Java program:

Click on the "Run" button at the top and look at the console window. You can also click on the "Run" menu and select the "Run" option.

How can we configure Eclipse to show the line number:

Windows -> Preferences -> General -> Editors -> Text Editors -> Show line numbers

How can we configure Eclipse to show heap space?

Windows -> Preferences -> General -> Show heap status

The heap size indicator on the lower right corner of your IDE. This indicator displays the maximum JVM heap size and how much of it is being used. Another useful feature of this indicator is the ability to garbage collect the heap. Simply click on the bin icon in the indicator to immediately schedule the heap for garbage collection. If you are lucky it will free up some heap space. There is also a context menu on this indicator. Simply right click to pop it.

How can we delete unwanted workspace?

Windows -> Preferences -> General -> Startup and Shutdown -> Workspaces.

Note that this does not actually delete the files from the system, it simply removes it from the list of suggested workspaces. It changes the org.eclipse.ui.ide.prefs.

How can we get Eclipse to re-recognize an old deleted workspace?

Just use the switch workspace functionality. Select Other and then select the old directory. This only works if you did not previously delete the directory associated with the old workspace.

How can we configure Eclipse to display two files so that their content are both visible at the same time?

Drag the tab for the file around until the cursor change to thick black arrow. You can split the screen vertically if you drag the tab to the right edge of the screen. You can split the screen horizontally if you drag the tab to the bottom edge of the screen.

How can we configure Eclipse to open the same file in multiple tab?

You can use right click on the tab, and chose New Editor. Changes that you make to one editor instance will be displayed in the other editor instances. However, you can scroll each editor instance independently.

How can we install a plugin?

  1. Go to Help -> Install New Software
  2. Click on the Add button
  3. Give it a name
  4. Provide the update URL
  5. Click OK
  6. Click "Select All"
  7. Select appropriate check boxes if necessary
  8. Click Next -> Next
  9. Accept the license agreements
  10. Click Finish

See http://www.youtube.com/watch?v=T7t5daTM-T8

Some plugin has a download page on which there is an install icon. You can drag this install icon and drop it onto a running Eclipse workspace to install the plugin.

How can we import a project using Subclipse?

  1. Right click on the Package Explorer
  2. Click on Import
  3. Drill down on SVN
  4. Click on "Checkout Projects from SVN"

How can we re-map a shortcut?

I've become increasingly annoyed that in order to run an ant script I have to use ALT + SHIFT + X,q. To re-map this shortcut to F7, click on Window > Preferences > General > Keys. Look for the "Run Ant Build" command (you should be able to use the filter box at the top to quickly locate the desired command). Click on the command, and then highlight everything in the Binding box and hit the Delete key and then press the F7 key and click OK.

Integration with Vim (Using Vim as an embedded editor inside Eclipse):

How can we get Eclipse to automatically generate setters and getters for a class?

  1. Right click anywhere in the editor
  2. Select Source -> Generate getters and setters.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License