Wiki source code of Debugging XWiki with IntelliJ Idea
Last modified by Vincent Massol on 2019/09/19 18:08
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{error}} | ||
| 2 | This setup has not been maintained by anyone over the years and is currently not working. We're keeping it in case someone wants to spend time to make it work again. | ||
| 3 | {{/error}} | ||
| 4 | |||
| 5 | This tutorial shows how to use IntelliJ Idea to setup a complete development environment for XWiki where you can develop, debug and test XWiki features without leaving the IDE. | ||
| 6 | |||
| 7 | This should work both with the Ultimate and the Community editions, that you can [[download here>>http://www.jetbrains.com/idea/download/index.html]] | ||
| 8 | |||
| 9 | == Step1: Clone and setup the xwiki-debug-idea project == | ||
| 10 | |||
| 11 | * Use git to clone the ##xwiki-debug-idea## repository | ||
| 12 | * In the same directory clone the [[##xwiki-platform##>>https://github.com/xwiki/xwiki-platform]] | ||
| 13 | * Go to the ##xwiki-debug-idea## project and run the ##init.sh## script. | ||
| 14 | ** The script should automatically detect the ##xwiki-platform## sources and create the needed links. | ||
| 15 | ** If you want to use an ##xwiki-platform## located elsewhere, you can tell the script to do so. | ||
| 16 | * If everything goes fine you should have something like that:((( | ||
| 17 | {{code}} | ||
| 18 | $ ls -l | ||
| 19 | total 24 | ||
| 20 | drwxr-xr-x 6 fm fm 4096 Oct 26 17:58 xwiki-debug-idea | ||
| 21 | drwxr-xr-x 5 fm fm 4096 Oct 26 11:14 xwiki-platform | ||
| 22 | |||
| 23 | $ cd xwiki-debug-idea | ||
| 24 | |||
| 25 | xwiki-debug-idea$ ./init.sh | ||
| 26 | XWiki platform sources found at /...somewhere.../xwiki-platform | ||
| 27 | Do you want to use this? (y/n) y | ||
| 28 | |||
| 29 | Creating symbolic links... | ||
| 30 | |||
| 31 | xwiki-debug-idea$ tree | ||
| 32 | . | ||
| 33 | ??? init.sh | ||
| 34 | ??? pom.xml | ||
| 35 | ??? src | ||
| 36 | ? ??? main | ||
| 37 | ? ??? resources | ||
| 38 | ? ? ??? logback.xml -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/resources/logback.xml | ||
| 39 | ? ??? webapp | ||
| 40 | ? ??? redirect -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/redirect | ||
| 41 | ? ??? resources -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources | ||
| 42 | ? ??? skins | ||
| 43 | ? ? ??? colibri -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-colibri/src/main/resources/colibri | ||
| 44 | ? ? ??? toucan -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-toucan/src/main/resources/toucan | ||
| 45 | ? ??? templates -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/templates | ||
| 46 | ? ??? WEB-INF | ||
| 47 | ? ??? cache -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/WEB-INF/cache | ||
| 48 | ? ??? fonts -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/WEB-INF/fonts | ||
| 49 | ? ??? hibernate.derby.cfg.xml.default | ||
| 50 | ? ??? hibernate.hsqldb.cfg.xml.default | ||
| 51 | ? ??? hibernate.mysql.cfg.xml.default | ||
| 52 | ? ??? hibernate.postgre.cfg.xml.default | ||
| 53 | ? ??? observation -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/WEB-INF/observation | ||
| 54 | ? ??? portlet.xml -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/WEB-INF/portlet.xml | ||
| 55 | ? ??? struts-config.xml -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/WEB-INF/struts-config.xml | ||
| 56 | ? ??? sun-web.xml -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/WEB-INF/sun-web.xml | ||
| 57 | ? ??? version.properties | ||
| 58 | ? ??? web.xml -> /...somewhere.../xwiki-platform/xwiki-platform-core/xwiki-platform-web/src/main/webapp/WEB-INF/web.xml | ||
| 59 | ? ??? xwiki.cfg.default | ||
| 60 | ? ??? xwiki.properties.default | ||
| 61 | {{/code}} | ||
| 62 | ))) | ||
| 63 | * Copy the one of the default ##hibernate.{derby,hsqldb,mysqls,postgre}.cfg.xml.default## to ##hibernate.cfg.xml##, depending on which database you want to use. | ||
| 64 | * Copy and review ##xwiki.cfg.default## to ##xwiki.cfg## | ||
| 65 | * Copy and review ##xwiki.properties.default## to ##xwiki.properties## | ||
| 66 | |||
| 67 | Now you should have a completely setup project, ready to be imported in IntelliJ Idea | ||
| 68 | |||
| 69 | == Step2: Importing into IntelliJ Idea | ||
| 70 | |||
| 71 | * Start IntelliJ Idea | ||
| 72 | * Choose "Open project" from the welcome screen and chose the ##pom.xml## of the ##xwiki-debug-idea## project. | ||
| 73 | |||
| 74 | [[image:open_project.png||width="480"]] | ||
| 75 | |||
| 76 | * Once dependency resolution is over, you can open the project structure dialog by choosing ##File -> Project structure...## from the menu. You should see, in the dependencies tab all the Maven dependencies needed to have the project run. | ||
| 77 | |||
| 78 | [[image:project.png||width="480"]] | ||
| 79 | |||
| 80 | * You can now create a run configuration for starting a Tomcat server and deploy XWiki | ||
| 81 | ** Open the "Edit configuration..." dialog by choosing ##Run -> Edit configurations...## | ||
| 82 | ** Expand the "Defaults" node, select "Tomcat" and then click on the "+" button on the right. (Note: you might need to have some plugins installed in order to have Tomcat available) | ||
| 83 | ** Fill the relevant fields in the dialog: | ||
| 84 | *** Put a meaningful name in the //Name// field (e.g. XWiki) | ||
| 85 | *** Put ##-XX:MaxPermSize=256m## in the //VM Options// field | ||
| 86 | *** Check the //Build artifact// checkbox | ||
| 87 | |||
| 88 | [[image:tomcat1.png||width="800"]] | ||
| 89 | |||
| 90 | * Open the "Deployment tab", click on the "+" button on the right and choose ##xwiki-debug-idea:war exploded## | ||
| 91 | |||
| 92 | [[image:tomcat2.png||width="800"]] | ||
| 93 | |||
| 94 | * You can set the application context on the right. By default it's set to ##/##. You might want to change this to ##/xwiki## | ||
| 95 | |||
| 96 | * Everything is setup for running XWiki. You can start it by clicking on the Run button or the ##Run -> Run...## menu item. Once run a browser should popup to the home page of your XWiki. | ||
| 97 | |||
| 98 | == Step3: Importing ##xwiki-platform## projects for hacking XWiki === | ||
| 99 | |||
| 100 | In the previous step you prepared everything for deploying and run XWiki. In doing so you are using the precompiled JARs downloaded from the Maven repositories. In this step you will import source code project so that you can modify XWiki and run a version containing your modifications (for testing and debugging) | ||
| 101 | |||
| 102 | * Open the //Project structure// dialog using the ##File -> Project structure...## menu item. | ||
| 103 | ** Click on the "+" button on the top and choose "Module" | ||
| 104 | |||
| 105 | [[image:project.png||width="480"]] | ||
| 106 | |||
| 107 | * Fill in the field in the "Add module dialog" | ||
| 108 | ** Navigate to the ##xwiki-platform## directory that contains the module that you want to work on (e.g. ##xwiki-platform-rest-server##) | ||
| 109 | ** Check the "Import maven project automatically" | ||
| 110 | ** Click "Next" several times to complete the import. | ||
| 111 | |||
| 112 | [[image:add_module.png||width="480"]] | ||
| 113 | |||
| 114 | * You will see the imported module appear in the project navigator on the left, in the main window | ||
| 115 | |||
| 116 | * Select all the projects in the tree, click with the right button on one of them and select ##Maven -> Reimport## | ||
| 117 | |||
| 118 | [[image:reimport.png||width="480"]] | ||
| 119 | |||
| 120 | * If everything went well, you should see in the project structure, in the dependencies tab that the Maven dependencies corresponding to the modules that you have imported in your project are now linked to the projects (they have a different icon). This means that the deployment will use the code you are actually developing in your IDE (and not the one coming from the JARs in your Maven repository) | ||
| 121 | |||
| 122 | [[image:dependencies.png||width="480"]] | ||
| 123 | |||
| 124 | == Step3: Hack XWiki! | ||
| 125 | |||
| 126 | You're done. You can now start writing and fixing code and test it from within Idea. | ||
| 127 | |||
| 128 | You can also start XWiki in debug mode (##Run -> Debug...##) and set breakpoints as you usually do. | ||
| 129 | |||
| 130 | Basically you can use Idea as you usually do and make it take care of handling all the complex dependencies behind XWiki. | ||
| 131 | |||
| 132 | Happy hacking. |