Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Wednesday, August 21, 2013

How to import existing project again in Eclipse?

How to import existing project again in Eclipse?

Assume there is a maven project ABCD in Eclipse workspace.
Now you have a requirement to import the same project of different version.
Since the project name is same for the existing and one you are trying to import now, Eclipse doesn’t allow you to do that and says – ‘Project ABCD is already imported into workspace.’

To solve this, one can use advanced options of maven project import like below:
  • Expand Advanced option
  • Check Resolve Workspace projects
  • In Name Template, there are already predefined options which you can use
  • Example: [artifactId] or [artifactId]-[version] etc. I prefer to override this a bit and do like this - [artifactId]-9.5.4 if the version of the project is 9.5.4. The reason is, if the version is snapshot version, then it’ll create the project something like ABCD-9.5.4-SNAPSHOT which I don’t like!

Thursday, October 4, 2012

Eclipse shortcuts





Monday, June 6, 2011

Continuous unit test runner

Came across the interesting Eclipse plug-in Infinitest, which on change of a source java file, runs the unit tests corresponding to that class.
If your class has good unit test coverage, you'll get to know the potential effect of your change on other dependant functionalities as soon as you save your changes on local.


You don't need to wait till you 
1) Build your project to see the breaking unit tests and
2) Do functional test to identify if your changes impact any other functionality (provided your class has good unit tests).


To add this plug-in to eclipse, just add the update site: http://infinitest.github.com


For more details, example video, you can verify this blog --> http://www.vasanth.in/2011/06/03/infinitest-a-continuous-test-runner-for-java/


Additional links:
http://infinitest.github.com/index.html
http://improvingworks.com/


Copy paste of text from Vasanth's blog:
Infinitest is an Eclipse plugin that runs the JUnit tests instantly when you save a Java file. Check out the demo above. It smartly runs only the test affected by the file you just saved. This is cool. You can immediately know if you broke something as soon as you save your code. Of course, your test cases should be comprehensive. Improving Works developed this plugin and has released it as a open source project.

Tuesday, May 24, 2011

Eclipse plugins

  • Findbugs --> http://findbugs.cs.umd.edu/eclipse/
  • Xpractise
    • The Eclipse plug-in XPairtise provides a platform for distributed pair programming. This plug-in offer shared editing, project synchronization, shared program and test execution, user management, built-in chat communication and a shared whiteboard.

    • Site: http://xpairtise.sourceforge.net
  • Jdeclipse (Java decompiler)
    • Site: http://jd.benow.ca/jd-eclipse/update
  • MoreUnit
    • MoreUnit is an Eclipse plugin that should assist you in writing more unit tests.
    • Site:http://moreunit.sourceforge.net/update-site/ 
  • Jetty --> http://run-jetty-run.googlecode.com/svn/trunk/updatesite
  • Regex Util --> http://regex-util.sourceforge.net/update/
  • Commonclipse
    • Commonclipse is an eclipse plugin for jakarta commons-lang users. It features automatic generation of the following methods using commons-lang builders:
    • toString()
    • hashcode()
    • equals(Object)
    • compareTo(Object)

    • Zip Site:http://sourceforge.net/projects/commonclipse/
    • Site:    http://commonclipse.sourceforge.net/
  • UML explorer (reverse engineering)
    • http://www.objectaid.com/installation

Thursday, March 3, 2011

Eclipse shortcut params

The following command line options are what I've found to work the best with Eclipse:

c:\path_to_eclipse\eclipse.exe -vm "C:\path_to_jvm\bin\javaw.exe" -Xmx512M -vmargs -DproxySet=true -DproxyHost=http.proxeee.ragsetty.com -DproxyPort=8888

-vm gives option to configure jdk version for your Eclipse

You can set these settings by creating a shortcut to eclipse.exe, right clicking on the shortcut, going to properties, and modify content of "Target" with above value.

These options will point to your installed JVM, set the proxy for updates, and prevent most out of memory errors by setting the maximum memory size for Eclipse to 512M.

Sunday, February 20, 2011

Tweaking Eclipse for LOG statements

Sometimes it’s good to revisit known/boring/old concepts! I just happened to read this article on Logging.

Particularly the section ‘Get your IDE to do the hard work’ caught my attention. Thought this'll add to my productivity in what ever little way!


I created these two little template xmls which you can import to your IDE. With this, we don’t need to write the same boiler plate code every time.

Advantages:

·         When I type in getlog and hit Ctrl+Space, Eclipse generates the following for me, with the proper class name filled:
private static final Log LOG = LogFactory.getLog(THE_CLASS_NAME.class);

·         When I type debug and hit Ctrl+Space, I get the complete if-block, and cursor placed inside the double quotes, ready to type the message.
if (LOG.isDebugEnabled()) {
    LOG.debug("msg");
}

·         When I type catch and hit Ctrl+Space, I get below:
catch (Exception e) {
    LOG.error("", e);
}
The same behavior also works if you use content assist for adding try catch block.

To get this, follow below simple instructions in your eclipse:
1.    Window -> Preferences -> Java -> Editor ->Templates
Click import, and import Java Editor Templates.xml
2.    Window -> Preferences -> Java -> Code Style -> Code Templates
Click import, and import Java Code Template.xml


Java Editor Templates:


<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <templates>
  <template autoinsert="false" context="java" deleted="false" description="catch block" enabled="true" id="org.eclipse.jdt.ui.templates.catch" name="catch">catch (${Exception} e) { LOG.error("${msg}", e); }</template>
  <template autoinsert="true" context="java" deleted="false" description="if (LOG.isDebugEnabled())" enabled="true" name="debug">if (LOG.isDebugEnabled()) { LOG.debug("${msg}"); }</template>
  <template autoinsert="true" context="java" deleted="false" description="Log LOG = LogFactory.getLog" enabled="true" name="getLog">${:import(org.apache.commons.logging.Log, org.apache.commons.logging.LogFactory)} private static final Log LOG = LogFactory.getLog(${enclosing_type}.class);</template>
  </templates>




Java Code Template:

  <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <templates>
  <template autoinsert="false" context="catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.catchblock" name="catchblock">LOG.error("", ${exception_var});</template>
  </templates>

Eclipse Save Actions

Eclipse IDE provides cool feature Save Actions.
On save of eclipse, we all know it compiles the class file in the background.

We can customize eclipse to do many more things like 
  • Organize imports
  • Remove unused imports
  • Add final modifier to private fields
  • Format source code
  • Remove unused local variables 
  • etc
Snapshot of my current configuration: