[[PageOutline(2-10,Table of Contents)]] = Compiling JOSM using IDE = This page describes how to compile the Java source code in IDE in order to get a runnable `josm-custom.jar` file. == Getting the Source == → [[Source code#Getthesource]] == Compiling == === Compiling using Ant === The easiest way to compile JOSM → [[Source code#CompilingusingAnt]] === Compiling using Eclipse + Maven === Download and install Eclipse: https://www.eclipse.org/ If you were previously using the `.project` and `.classpath` file that were in source control, you must first remove the old project (right-click -> `Delete` -> `OK` -- DO NOT check `Delete project contents on dist (cannot be undone)`). You will want to use `File` -> `Import...` -> `Existing Maven Projects` -> root source directory -> leave all `Projects` checked. Once the import finishes, you ''may'' want to run `Update Project...` (right click on a project -> `Maven` -> `Update Project...` -> `Select All` -> `OK`) since that will regenerate various Eclipse files. === Compiling using Eclipse (old) === Download and install Eclipse: https://www.eclipse.org/ Use Eclipse and the provided `.project` and `.classpath` file. Just import project using the JOSM core folder as root directory. You will have problems compiling, due to problems compiling Mappaint MapCSS with a fresh install of Eclipse. First you will need the [https://javacc.github.io/javacc/faq.html JavaCC] [http://eclipse-javacc.sourceforge.net/ plugin for Eclipse]. To install it in Eclipse, go to Help->New Software... then add the site [http://eclipse-javacc.sourceforge.net/] as a source, and install the JavaCC Eclipse Plug-in. Then in the Package Explorer, expand org.openstreetmap.josm.gui.mappaint.mapcss, right-click on MapCSSParser.jj, and "Compile with JavaCC". This should put new java files in a package called org.openstreetmap.josm.gui.mappaint.mapcss.parsergen, but if it doesn't, you will have to create the package manually (right-click and create package), then drag the new files into the package you just created (they should be easy to identify based on the light gray text that denotes it was compiled from MapCSSParser.jj). This should resolve any import issues in MapCSSStyleSource.java, and you should now be able to compile JOSM. You may need to install the IvyDE eclipse addon. In recent versions of Eclipse, you have to use the IvyDE [http://www.apache.org/dist/ant/ivyde/updatesite update site] (now [https://archive.apache.org/dist/ant/ivyde/updatesite/ archived]) to install the addon. Once installed, right click on the JOSM project, go to "Ivy", and then "Resolve". Before being able to run JOSM from eclipse, you need to compile the project using `ant epsg-compile` one time. Otherwise, you will get a resource not found error on startup. If you try to compile the JOSM sources in Eclipse and get errors like "The method marktr(String) is undefined for the type SomeType" look at [https://lists.openstreetmap.org/pipermail/josm-dev/2008-August/001585.html solution suggested at mailing list]. There are also two Videos available at youtube, which show [https://www.youtube.com/watch?v=-LoWGf-hqiQ how to checkout JOSM into Eclipse] and [https://www.youtube.com/watch?v=Z3OjG3nDvzA how to checkout a JOSM plugin into Eclipse]. === Compiling using Gradle + Eclipse === Not officially supported. 1. Delete `.settings`, `.project`, `.classpath` files/dirs 2. Download the zip file with the gradle build files form #8269 and extract it into your JOSM directory. 3. Then in eclipse, go to `File` -> `Import` -> `Existing Gradle project` and select the JOSM directory. You can start JOSM using the `run` target of gradle (found in the `Gradle Tasks` view). === Compiling using Netbeans === 1. Download and install Netbeans: https://netbeans.org/ 2. File → Open Project 3. Navigate to the JOSM source code (see [[#GettingtheSource]]), subdirectory `ide/netbeans/` [[BR]] [[Image(netbean-open2.png​)]] 4. Use `1` to compile, `2` to clean and compile, and `3` to run JOSM: [[BR]] [[Image(netbeans-compile-run.png)]] 5. Note that the build needs to be run twice! (The first build will write ivy.classpath in project.properties, second build will read it.) === Compiling using ​IntelliJ IDEA === → [[DevelopersGuide/CompilingUsingIntelliJ]] == Unit Tests == It is most convenient, to run tests from an IDE like Eclipse or Netbeans. There is also an ant task to run all tests (but you cannot rerun individual tests). All unit tests can be run in headless mode (i.e, without a graphic display), allowing them to be run in continuous integration projects. === Running Test from Command line === ==== Prerequisites ==== Here are some of the tools you will need for installing under most linux operating systems. Tools: ant, java jdk/jre 8, junit Example install for Ubuntu Linux: {{{ #!sh sudo apt-get install ant openjdk-8-jdk junit # please install these ahead, you definitely need them }}} ==== All tests ==== The quickest way to run the tests is done using the 'ant' build system. {{{ #!sh ant clean test # this will run through all 200+ tests marking them sucessful, failure, in error, or skipped. }}} ==== Individual tests ==== You can run individual tests from the command line, as well. For instance, to run `ProjectionRefTest` only: {{{ #!sh ant test '-Ddefault-junit-includes=**/ProjectionRefTest.class' }}} ==== Individual tests (complex variant) ==== You can run individual tests from the command line, as well. Include all libraries in the class path like this: {{{ #!sh export TESTCP=".:test/unit:test/functional:dist/josm-custom.jar:test/lib/commons-testing/*:test/lib/fest/*:test/lib/junit/*:test/lib/*:test/lib/unitils-core/*" export TESTCP=$TESTCP:"tools/*:tools/spotbugs/*:test/lib/reflections/*:tools/pmd/*" # added these missing directories. Without it will fail to run. }}} Here are a few build and run instructions for some example tests: {{{ #!sh # Projections Reference Test javac -cp $TESTCP test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java java -cp $TESTCP org.junit.runner.JUnitCore org.openstreetmap.josm.data.projection.ProjectionRefTest # Download GPS Task Test javac -cp $TESTCP test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java java -cp $TESTCP org.junit.runner.JUnitCore org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTaskTest }}} On Windows the syntax is almost the same: {{{ #!sh set TESTCP=".;test/unit;test/functional;dist/josm-custom.jar;test/lib/commons-testing/*;test/lib/fest/*;test/lib/junit/*;test/lib/*;test/lib/unitils-core/*;tools/*;tools/spotbugs/*" javac -cp %TESTCP% test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java java -cp %TESTCP% org.junit.runner.JUnitCore org.openstreetmap.josm.data.projection.ProjectionRefTest # and similar for the Download GPS Task Test javac -cp %TESTCP% test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java java -cp %TESTCP% org.junit.runner.JUnitCore org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTaskTest }}}