Skip to content, Skip to search

Changes

Developing ImageJ in Eclipse

2,798 bytes added, 14 March
m
Adding useful video tutorial for setup
{{Development DevelopMenu | tutorials}}<div style="float: left; padding-right: 1em">__TOC__</div>This article explains how to install, configure and use Eclipse to develop [[ImageJ]] [[components]] and [[plugins]]. Directions correspond to Eclipse 4.4 Luna, and may need adjustment for other versions.<div style="clear: left"></div>
= Initial setup =
=== Configure Eclipse for your platform ===
<table div style="widthoverflow: 99%hidden"><trtabs><td styletab name="vertical-align: top; width: 33%Windows">{{ExpandingBox| [[File:Win.png | x32px]] '''Windows'''| '''Avoid permissions issues.''' We recommend installing Eclipse ''outside'' of the <code>Program Files</code> directory. E.g.: '''<code>C:\Users\frood\Programs\eclipse</code>''', where '''<code>C:\Users\frood</code>''' is your user directory.
'''Configure Eclipse.''' After installing Eclipse, you will need to configure it to know about your JDK.
* Click Search..., navigate to your JDK installation folder (e.g., '''<code>C:\Program Files\Java\jdk1.8.0_11</code>''') and click OK
* Check the box next to the JRE that appears and click OK
}}</tdtab><td styletab name="vertical-align: top; width: 33%OS X">{{ExpandingBox| [[File:Osx.png | x32px]] '''OS X'''| '''Understand Java 6 vs. Java 8.''' Eclipse should work on OS X with no further configuration. However, we recommend reading the [[FAQ#Mac_OS_X|OS X section of the FAQ]], as there are several Java-related issues on OS X.}}</tdtab><td styletab name="vertical-align: top; width: 33%Linux">{{ExpandingBox| [[File:Tux.png | x32px]] '''Linux'''| '''Avoid permissions issues.''' We recommend installing to <code>$HOME/eclipse</code>.
'''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.
 '''Adjust the Eclipse font size.''' Sometimes it is desirable to change the Eclipse font size. To do so, create a GTK configuration file (e.g. <code>~/.gtkrc-eclipse</code>) and place the following lines there: style "eclipse" { font_name = "Sans Condensed 8" }} class "GtkWidget" style "eclipse"  Then run eclipse using this command: <code>GTK2_RC_FILES=~/.gtkrc-eclipse eclipse</code></tdtab></trtabs></tablediv>
== Clone the source code ==
* Using your [http://git-scm.com/downloads/guis Git client of choice], clone the source code which interests you: * If you want to work on an existing project, see the [[source code|list of sources]] which interests .* If youare creating your own project, see the [[building a pom]] guide.
== Import the source code ==
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.
 
If you're having trouble, how to import and build your Maven + Eclipse project, follow this video: [https://www.youtube.com/watch?v=YIWpoBnnLio How To Setup and Make a Fiji Plugin]
= The Run-Debug cycle =
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|Shift|T}}
| open Open a Java class from the workspace
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|Shift|R}}
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|F3}}
| jump Jump to selected class<br>(to edit the code, see [[Architecture#Using_snapshot_couplings_during_development|snapshot coupling]])
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|O}}
| Shows Show superclass/subclass hierarchy
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|T}}
| show Show implementations of interface or class
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|L}}
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|Q}}
| GO Go to last edit location
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|E}}
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Alt|Up}}, {{Key|Alt|Down}}
| move Move current line up or down
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|D}}
| delete Delete the current line
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|/}}
| commentComment/uncomment the selected line(s)
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|1}}
| quick Quick fix selected error
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|Space}}
| autoAuto-complete current selection
|-
| colspan=2 style="padding-top: 1em" | '''Code cleanup'''
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|Shift|O}}
| organize Organize imports
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|Shift|F}}
| format Format code<br>(BUT make sure you set the [[Coding_style#Eclipse_code_style_profiles|coding style]])
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Alt|Shift|S}}, {{Key|U}}
| clean Clean up (does format and much more)
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Alt|Shift|R}}
| refactorRefactor/rename selected class/variable
|-
| colspan=2 style="padding-top: 1em" | '''Debugging'''
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|Ctrl|Shift|B}}
| Set/Remove Breakpointbreakpoint
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|F5}}
| Step Intointo
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|F6}}
| Step Overover
|-
| style="text-align: right; vertical-align: top; white-space: nowrap" | {{Key|F7}}
| Step Outout
|}
</div>
# Scroll down to Maven Build. If you've built this project with Maven via Eclipse before there will already be a configuration for it. Otherwise you can double-click "Maven Build" to create a new run configuration.
# Add a parameter: <code>imagej.app.directory</code> with value: <code><path/to/ImageJ.app></code> (e.g. <code>/home/hinerm/Fiji.app</code>)
# Add a parameter: <code>deleteimagej.other.versionsdeleteOtherVersions</code> with value: <code>truealways</code>
# Click <code>Apply</code>
==Adding new plugins==
The easiest method is to start with a [https://github.com/imagej/minimalexample-ij1legacy-plugin/zipball/master minimal project], renamed to the desired name of your plugin. By convention, the project directory should match the base name of the <code>.jar</code> file to be generated.
The format of such a <code>pom.xml</code> is described briefly on the [[Maven]] page.
After that, ask Eclipse to import it: {{bc | File | Import | Maven | Import Existing Maven Project}}.
 
==Viewing Dependency Source==
 
When jumping into a dependency class in Eclipse (using {{Key|F3}}), you may see a message stating "Source not found".
 
For Maven dependencies there must be a <code>-sources</code> classifier JAR in the repository along side the main JAR. For example, <code>imagej-common</code> has an <code>imagej-common-0.24.4.jar</code> and an <code>imagej-common-0.24.4-sources.jar</code>. In theory, the Eclipse M2E plugin should download this <code>-sources</code> JAR and automatically display it to you when you jump to the class.
 
However, if for some reason this doesn't happen you can try the following steps.
 
#Try right-clicking the JAR in the Maven dependencies in Eclipse, and selecting "Download Sources". This should force Eclipse to download the <code>-sources</code> JAR.
#Check that the <code>-sources</code> JAR has been downloaded locally.
#* Navigate to <code><path-to-.m2-repo>/repository/<groupId>/<artifactId>/<version></code> and see if there is a <code>-sources</code> JAR there.
#* If it is not, then in a terminal navigate to the folder containing your project's pom.xml file. And then from the command line run <br /><code>mvn dependency:get -Dartifact=groupId:artifactId:version:packaging:classifier</code>.
#**For example if a project depended on imagej-common and you needed to retrieve the <code>-sources</code> JAR, the command you'd type would be:<br /> <code>mvn dependency:get -Dartifact=net.imagej:imagej-common:0.24.4:jar:sources</code>
#If the <code>-sources</code> JAR was there, you could check its contents by running the following command from the terminal:<br /><code>jar tr <path-to-.m2-repo>/repository/<groupId>/<artifactId>/<version>/<jar-name>-sources.jar</code>.
#*If the file in question isn't there, then unfortunately this project doesn't have source for that class.
 
If the class you're trying to view is a part of the JRE and you're on Linux, you may need to run <code>sudo apt install openjdk-<java-version-number>-sources</code> to retrieve the sources.
 
Note that doing this only allows you to view the source code, it does '''not''' allow you to edit it. If you need to edit these files, see the [[Architecture#Using_snapshot_couplings_during_development|snapshot coupling]] section for more information.
== See also ==
* [[How to contribute to an existing plugin or library|Contributing to a plugin]]
|
* {{GitHub|org=imagej|repo=minimalexample-ij1legacy-plugin|label=minimalexample-ij1legacy-plugin}} project template* [[Introduction into Developing Pluginsfor ImageJ 1.x]]
|}
[[Category:Development]]
[[Category:IDEs]]