Skip to content

Instantly share code, notes, and snippets.

@gkhays
Last active August 19, 2024 13:05
Show Gist options
  • Save gkhays/3cd9b68010041d590f8be1b26a07a55f to your computer and use it in GitHub Desktop.
Save gkhays/3cd9b68010041d590f8be1b26a07a55f to your computer and use it in GitHub Desktop.
Eclipse Tricks

Eclipse Tips and Tricks

My collection of Eclipse tips and tricks. I also have an Eclipse Cheat Sheet.

Change Context Root

Change the context root in an Eclipse Dynamic Web project.

Once you do this it is necessary to clean up the deployed resources. This may be accomplished in the server view, e.g. choose Window >> Show View >> Servers.

Click OK in the confirmation dialog.

See also How to change context root of a dynamic web project in Eclipse?

Generate Deployment Descriptor

Right click on Deployment Descriptor in Project Explorer.

See also web.xml is missing.

You can also get to it with the Project >> Properties >> Java EE Tools right click context menu.

Code Coverage for Eclipse

Coverage

Clear

Tomcat Settings

Typically applications are deployed to .metadata/.plugins/org.eclipse.wst.server.core/tmp0. You can customize this in the Tomcat server configurationby double-clicking on the Tomcat server.

See also:

Change Source Folder

To switch to a Maven-style layout of src/main/java first remove the reference to src by right mouse-clicking on it and selecting build path >> remove from build path. At this point src will appear as a regular folder.

Next create the main and java folders under src. Move the existing files. Finally, right mouse-click on the new java folder and select build path >> use as source folder.

See also:

JUnit View in Eclipse

Where to put the JUnit tab?

Using Maven Generated Source in Eclipse

One of the things I really hate is the little red error icons when I am working on a Maven project in Eclipse. One of the "gotchas" is using Maven-generated source code.

I added the following plugin to pom.xml in the build section.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/generated-sources/java/</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

Window -> Preferences -> Maven -> Discovery

I ran that and it suggested the Maven Integration for Eclipse JDT APT plugin, so I installed it too.

You will also need to:

Install the "Apt M2E Connector" from the Eclipse Marketplace. Ensure there are no plugin execution filters for the build-helper-maven-plugin (see http://wiki.eclipse.org/M2E_plugin_execution_not_covered).

@gkhays
Copy link
Author

gkhays commented Mar 30, 2016

I've spent some time getting Eclipse to where I like it, so I'm passing along some of the knowledge.

@gkhays
Copy link
Author

gkhays commented Oct 12, 2019

eclipse-coverage

@gkhays
Copy link
Author

gkhays commented Oct 12, 2019

remove-all-sessions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment