Difference between revisions of "Developing ImageJ in Eclipse"

(Tweak intro; add "See also" section)
(Import the source code: Add note about how warnings are often normal, stolen from the old "Developing Fiji in Eclipse" page)
Line 115: Line 115:
 
# Browse to the folder where you cloned the project source code
 
# Browse to the folder where you cloned the project source code
 
# Click Finish
 
# Click Finish
 +
 +
Eclipse will import and automatically build the project(s). There should not be any build errors, but it is normal to see a large number (often hundreds) of warnings. These mostly come from Java-1.4-style code or unnecessary imports, variables or methods in the sources of authors who do not use an IDE and thus have no automatic assistance at cleaning up. All these warnings can be ignored, having no effect on the functionality of the code.
  
 
== Launch ImageJ ==
 
== Launch ImageJ ==

Revision as of 14:51, 2 December 2015

Template:DevelopmentThis article explains how to install and configure Eclipse to develop ImageJ components and plugins. Directions correspond to Eclipse 4.4 Luna, and may need adjustment for other versions.

Install and configure Eclipse

Install the Java Development Kit

  • Download and install the Java Development Kit (JDK) from the Java web site.

Install Eclipse



  • Unpack the archive to a location of your choice.

Configure Eclipse for your platform

Win.png Windows
Avoid permissions issues. We recommend installing Eclipse outside of the Program Files directory. E.g.: C:\Users\frood\Programs\eclipse, where C:\Users\frood is your user directory.

Configure Eclipse. After installing Eclipse, you will need to configure it to know about your JDK.

Use Wordpad to edit the eclipse.ini file in your Eclipse installation (e.g., C:\Users\frood\Programs\eclipse). (Do not use Notepad, because it will not handle the Unix-style line breaks properly.) Carefully follow these instructions to specify the proper JDK. Then save the file and quit Wordpad.

Now update Eclipse's JRE to be JDK-aware:

  • Launch Eclipse
  • From the menu choose Window  › Preferences
  • Select Java  › Installed JREs
  • Click Search..., navigate to your JDK installation folder (e.g., C:\Program Files\Java\jdk1.8.0_11) and click OK
  • Check the box next to the JRE that appears and click OK


Osx.png OS X
Understand Java 6 vs. Java 8. Eclipse should work on OS X with no further configuration. However, we recommend reading the OS X section of the FAQ, as there are several Java-related issues on OS X.


Tux.png Linux
Avoid permissions issues. We recommend installing to $HOME/eclipse.

Do not use a package manager. For several reasons, we do not recommend installing Eclipse from a package manager. You may not get a new enough version of Eclipse (we recommend 4.3+), you will not get the Java Developers version that includes the M2E plugins, and you will likely have trouble installing additional plugins due to the permissions issues with the system-wide installation.


Keyboard shortcuts

On OS X, replace ^ Ctrl with Cmd

Navigation
^ Ctrl+ Shift+T open a Java class
^ Ctrl+1 quick fix
F3 jump to class
(to edit the code, see snapshot coupling)
^ Ctrl+O show outline
^ Ctrl+Space auto-complete
^ Ctrl+T show implementations of interface or class
Editing
Alt+, Alt+ move current line up or down
^ Ctrl+D delete the current line
^ Ctrl+/ comment/uncomment the selected line(s)
Code cleanup
^ Ctrl+ Shift+O organize imports
^ Ctrl+ Shift+F format code
(BUT make sure you set the coding style)
Alt+ Shift+S, U clean up (does format and much more)
Alt+ Shift+R refactor rename

Clone the source code

Import the source code

  1. Choose File  › Import from the Eclipse menu
  2. Select "Existing Maven Projects" and click Next
  3. Browse to the folder where you cloned the project source code
  4. Click Finish

Eclipse will import and automatically build the project(s). There should not be any build errors, but it is normal to see a large number (often hundreds) of warnings. These mostly come from Java-1.4-style code or unnecessary imports, variables or methods in the sources of authors who do not use an IDE and thus have no automatic assistance at cleaning up. All these warnings can be ignored, having no effect on the functionality of the code.

Launch ImageJ

If you cloned the imagej project, you can launch the program as follows:

  1. In the Package Explorer, expand the imagej project
  2. Navigate into src/main/java
  3. Navigate into net.imagej
  4. Right-click on Main.java
  5. Choose "Run As" and then "Java Application"

Other projects will have different main classes.

See also

ImageJ2 ImageJ 1.x