Setup via IntelliJ

Hi!

I’m trying to obtain travel times & distances for a research project via Graphhopper (am new to Java/IntelliJ etc). I’ve tried to follow the instructions here using IntelliJ: https://github.com/graphhopper/graphhopper/blob/master/docs/core/routing.md

I created a new project in IntelliJ, set up the Maven dependencies and am not sure how to proceed. Am I missing steps? Where do I add the lines of code (I tried adding a java class file in src>main and pasted the code but it’s not recognizing any of the classes)?

Thanks,
Grace

I can only guess what problem you are facing, but make sure to do: File->New Project->From existing sources... and then choose the top level pom.xml file. This way IntelliJ should automatically recognize its a maven project and recognize the classes etc.

Oh or maybe all you want to do is use GH in your project ? In this case add the maven dependencies to your pom.xml (in case you are using maven, which is the easiest). You can check if everything is set up correctly by running mvn compile for example.

Hi, thanks for your replies! So I think I successfully opened the project: image

If I want to add in ‘the lines of code’ do I add a new java file under core > src > main > java?

Yes, for example create a Main.java with a main method inside src/main/java and copy&paste the code from the link you posted. If you only want to use (not modify) the GH code you can also create an empty project and only include GH as (maven) dependency.

Thanks! (Hopefully the last question): Do you know why these four symbols in red can’t be resolved?

image

You are missing a main function, try like this:

public class Main {

    public static void main(String[] args) {
       GraphHopper hopper = new GraphHopperOSM();
       hopper.setDataReaderFile(...);
       ...
    }
}

IntelliJ should then show a little green play button next to the main function you can use to run the code

Powered by Discourse