Java mode extension for Emacs. Extends java-mode build source code and run tests with Maven.
git clone [email protected]:nchapon/javax-mode.el
You need to have installed Java and Maven and setup two environments variables by default in .bash_profile
- set
JAVA_HOME
to target Java home directory - add
mvn
commnand in yourPATH
Add this in your emacs configuration
;; Set up ENV variables to have the same as bash
(when (file-exists-p "~/.bash_profile")
(setenv "JAVA_HOME" (shell-command-to-string "source ~/.bash_profile; echo -n $JAVA_HOME"))
(setenv "PATH" (shell-command-to-string "source ~/.bash_profile; echo -n $PATH")))
(require 'javax-mode)
The only requirement is to have a Java Maven project.
Keybinding | Description |
---|---|
C-c j t | Jump between test and code |
C-c j s | Open source file |
C-c j o | Organize imports |
C-c j x t | Run JUnit tests for buffer |
C-c j c | Compile source code from mvn command line mvn -o compile |
C-c j c | Build project from mvn command line mvn -f <pom-parent> clean install |
Flycheck can be use to check java syntax on the fly with Eclipse Compiler for Java (ECJ)
ECJ is running in batch mode each time the source code is modified in a Java buffer.
The Java classpath is built from maven command mvn dependency:tree
- Configure
jx/mvn-repo-path
with your maven repository :
(setq jx/mvn-repo-path "/home/nchapon/opt/m2_repo")
- Configure
jx/ecj-path
to target ECJ executable tool
(setq jx/ecj-path "/home/nchapon/opt/bin/ecj-4.3.2.jar")
- You should have a valid Java Maven Project.
- Open any Java file from this project and type jx/update-config. This will generate a file .javax-project.el used to configure java classpath and ECJ options.
In any java buffer simply enable flycheck mode, enter M-x flycheck-mode.
- At this moment could not work with Lombok
You will find the source code at : https://github.com/nchapon/javax-mode.el
Tests are written with Ecukes. This library is used to write Cucumber-like tests for Emacs.
- Install Cask
- Run cask to install all dependencies :
$ cd /path/to/javax-mode
$ cask
- Run all the tests
$ cask exec ecukes --no-win
- Flycheck : create javax project config file if does not exist before running flycheck
- Flycheck : add hook after save maven config file to update project config
- Flycheck : customize JVM / ECJ options
- Inline variables in source code
- Organize imports : customize imports order
- Display class method names
- Extend navigate to source code in dependencies
- Add a real autocomplete mode
- Can execute test not only from test case but from java source code under test buffer
- Flycheck should work with lombok