Trucs & astuces — JAVA et Eclipse
How do I activate Java assertion mechanism ?
- Add the option -ea to the java execution command.
-
In Eclipse, two possibilities:
- To run a class or a JUnit test, in the menu Run as, choose Run configurations..., then open the l'onglet Arguments et dans le formulaire VM arguments, ajoutez l'option -ea.
- Pour toutes les exécutions, dans le menu global Window/Preferences, choisir la page Java/Installed JREs, puis dans la page Edit de celle qui est sélectionnée, dans le formulaire Default VM arguments, ajoutez l'option -ea.
J'utilise Eclipse pour m'aider à définir les méthodes equals, hashCode et toString, ainsi que les getters et les setters
Une fois le contenu d'une classe ouvert, menu Source,
puis generate...
Je configure le greffon Checkstyle
- Récupération du fichier, selon la version d'eclipse:
-
Configuration de Checkstyle dans Eclipse :
- Menu Window / Preferences / Checkstyle ; créez une nouvelle configuration en sélectionnant New puis en choisissant External Configuration File, en recherchant (Browse) le fichier sun_checks_adapted_to_tsp_csc*.xml (l'un ou l'autre) et en donnant un nom à cette nouvelle configuration ; une fois la création de la nouvelle configuration validée (bouton OK), sélectionnez-la et cliquez sur le bouton Set as Default. Pour exécuter l'analyse du code par Checkstyle, c'est le menu contextuel Checkstyle / Activate Checkstyle.
I cannot start Eclipse (because I have used an older version)
You can try the following actions. Start with the first one, and
perform the actions incrementaly with some testing after each
action:
- Remove your configuration of Eclipse: rm -rf ~/.eclipse.
- Remove your locally intalled Eclipse plugins: rm -rf ~/.p2.
- Change the Eclipse workspace, which may be corrupted: e.g. mv ~/workspace.
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-dependency-plugin:2.8:unpack (execution: unpack, phase: process-classes)
Open the pom.xml file to see the error. Eclipse
says that the life-cycle phase that is named "process-classes"
is unknown (to the M2Eclipse plugin that manages the Maven build
process in Eclipse).
- On the error, use the "quick fix" functionality of Eclipse. It proposes to install a plugin for managing unknown phase "process-classes". Install the proposed plugin: e.g. the plugin com.ianbrandt.tools.m2e.mdp.core*.jar, and restart Eclipse.