Difference between revisions of "Eclipse"

Line 103: Line 103:
 
At the bottom of the script, choose "UTF-8"
 
At the bottom of the script, choose "UTF-8"
  
[[File:Eclipse utf8 encoding 1.png|frameless|Eclipse UTF-8 encoding(1)]]
+
[[File:Eclipse utf8 encoding 1.png|none|Eclipse UTF-8 encoding(1)]]
  
 
Window menu -> Preferences -> General -> Editors -> Text Editors -> Spelling
 
Window menu -> Preferences -> General -> Editors -> Text Editors -> Spelling
Line 114: Line 114:
 
Encode CSS + HTML + JSP + XML in UTF-8
 
Encode CSS + HTML + JSP + XML in UTF-8
  
[[File:Eclipse utf8 encoding 3.png|frameless|Eclipse UTF-8 encoding(3)]]
+
[[File:Eclipse utf8 encoding 3.png|none|Eclipse UTF-8 encoding(3)]]
  
 
On the General -> Content Types, check that everything has default encoding: UTF-8.
 
On the General -> Content Types, check that everything has default encoding: UTF-8.
Line 132: Line 132:
 
*** JSP Tag definition
 
*** JSP Tag definition
 
** XML
 
** XML
 +
 +
 +
==Code formatting==
 +
===Import formatter===
 +
Window menu -> Preferences -> Java -> Code style -> Formatter
 +
    > Import formatter 
 +
 +
[[File:eclipse_formatter.png|none|Eclipse formatter]]
 +
 +
===Save actions==
 +
Before saving a java file, you can perform some "save actions", that will result in automatic formatting.
 +
 +
Window menu -> Preferences -> Java -> Editor -> Save Actions
 +
Enable Perform the selected actions on save
 +
 +
[[File:eclipse_save_actions.png|none|Eclipse save actions]]
 +
 +
Check:
 +
* Perform save actions
 +
** Format source code
 +
*** format ALL lines
 +
** Organize imports
 +
** Additional actions
 +
 +
... Configure additional actions:
 +
*Code organizing
 +
*Remove trailing whitespace (all lines)
 +
*Correct indentation
 +
*Sort members
 +
*Code style
 +
**Use block in if/while/for/do statements (always)
 +
**Use modifer "final" where possible (parameter)
 +
*Missing code
 +
**Select all
 +
*Unnecessary code
 +
**Remove unused imports
 +
**Remove unnecessary casts + '$NON-NLS' tags
  
 
==JavaHL for Subclipse==
 
==JavaHL for Subclipse==

Revision as of 12:35, 26 January 2014

Requirements

Eclipse requires a Java JDK to work. See Java JDK setup


Installation

Download eclipse from the official website: http://eclipse.org/downloads/

Take the Eclipse IDE for Java EE developers version.


Windows

Just extract the archive and run ./eclipse/eclipse.exe


Linux

Basic installation

  • Download the eclipse.deb package
  • Install the package using:
tar -xzvf eclipse.tar.gz
  • Launch application by running ./eclipse/eclipse


Create a desktop launcher

sudo vim /usr/share/applications/eclipse.desktop

Put the following content where /home/guillaume/DEV/eclipse is the path to Eclipse.

[Desktop Entry]
Version=4.3.0
Name=Eclipse
Comment=Eclipse IDE
Exec=/home/guillaume/DEV/eclipse/eclipse -clean
Icon=/home/guillaume/DEV/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=Utility;Application


Ubuntu 13.10 - launcher Fix

If the menu doesn't appear correctly you must create the following launcher:

[Desktop Entry]
Version=4.3.0
Name=Eclipse
Comment=IDE for all seasons
Exec=env UBUNTU_MENUPROXY=0 /home/guillaume/DEV/eclipse/eclipse -clean
Icon=/home/guillaume/DEV/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=Utility;Application

Don't forget the Exec=... line! The key is "env UBUNTU MENUPROXY=0"


SWT libraries fixes

On the latest distribution Eclipse sometimes crashed due to libswt-*.so

To resolve that, install the development libraries:

apt-get install libx11-dev libxtst-dev libgl1-mesa-dev libglu1-mesa-dev libgtk-3-dev


Eclipse configuration

JDK

Window menu -> Preferences -> Java -> Installed JRE

    > Add the JDK as a standard VM
    > JRE home = JDK root
    > Click "Finish"

Select the new JDK as the default one

Preferences -> Java -> Installed JRE -> Execution Environment

    > For each java version adjust the JVM to use

Display line numbers

Window menu -> Preferences -> General -> Editors -> Text Editors

    > Enable show line numbers 
    > show print margin (you can adjust the size. I'm using "160")

Increase console size

Window menu -> Preferences -> Run / debug -> Console

If you limit the console output put a hudge value (>= 100 000)


Adjust encoding to UTF-8

By default Eclipse use the same encoding as your O.S, which is probably ISO-8859-1 .You should instead use UTF-8.

Window menu -> Preferences -> General -> Workspace

At the bottom of the script, choose "UTF-8"

Eclipse UTF-8 encoding(1)

Window menu -> Preferences -> General -> Editors -> Text Editors -> Spelling

Choose UTF-8 to encode javadoc

Eclipse UTF-8 encoding(2)

Window menu -> Preferences -> General -> filter "encoding"

Encode CSS + HTML + JSP + XML in UTF-8

Eclipse UTF-8 encoding(3)

On the General -> Content Types, check that everything has default encoding: UTF-8. If the default encoding is blank, then add "UTF-8"

Check:

  • Android Binary XML (if available)
  • Diagram (if available)
  • JAR Content
  • Java class File
  • Text
    • HTML
    • Java properties file
    • JSP
      • CSS JSP
      • JSP fragment
      • JSP Tag definition
    • XML


Code formatting

Import formatter

Window menu -> Preferences -> Java -> Code style -> Formatter

    > Import formatter  
Eclipse formatter

=Save actions

Before saving a java file, you can perform some "save actions", that will result in automatic formatting.

Window menu -> Preferences -> Java -> Editor -> Save Actions Enable Perform the selected actions on save

Eclipse save actions

Check:

  • Perform save actions
    • Format source code
      • format ALL lines
    • Organize imports
    • Additional actions

... Configure additional actions:

  • Code organizing
  • Remove trailing whitespace (all lines)
  • Correct indentation
  • Sort members
  • Code style
    • Use block in if/while/for/do statements (always)
    • Use modifer "final" where possible (parameter)
  • Missing code
    • Select all
  • Unnecessary code
    • Remove unused imports
    • Remove unnecessary casts + '$NON-NLS' tags

JavaHL for Subclipse

Source: Subclipse JavaHL wiki

Linux requires the JavaHL client for Subclipse:

sudo apt-get install libsvn-java

Find the library file:

sudo find / -name libsvnjavahl-1.so

You should have something like:

guillaume@VC076:~/DEV/eclipse$ sudo find / -name libsvnjavahl-1.so
/usr/lib/x86_64-linux-gnu/jni/libsvnjavahl-1.so

Now, update your eclipse.ini configuration

vim eclipse.ini

Add the path without '/' at the end.

-vmargs
-Djava.library.path=/usr/lib/x86_64-linux-gnu/jni

→ Note: Ubuntu 13.10 as only the JavaHL 1.7 library. So you should not install SVN client 1.8.x but SVN client 1.7.x !!