Graphhopper helloworld in Eclipse

I’m trying to work with the graphhopper library. I’ve imported the .jar in eclipse. However, I am getting the ‘graphhopper cannot be resolved to a type’ error. What do I need to put in my code to make it understand the GraphHopper is there? I’m pretty sure it’s some kind of ‘include’ or ‘import’ type line but I don’t know which one.

My code is just this for now:

public class hello {

public static void main(String[] args) {
	System.out.println("hi");
	
	String workDir = "";
	String vehicle = "";
	String osmFile = "";
	
	graphHopper = new GraphHopper().setGraphHopperLocation(workDir) // "gh-car"
		    .setEncodingManager(new EncodingManager(vehicle) // "car"
		    .setOSMFile(osmFile) // "germany-lastest.osm.pbf"
		    .forServer();

}

}

Ok, I got a bit further by adding

import com.graphhopper.GraphHopper;
import com.graphhopper.routing.util.EncodingManager;

However, there are other problems with the code. It seems to think that ‘setencodingmanager’ returns an encoding manager but looking at the code is seems that it should just return graphhopper. Anyone know how to make this work?

In general, is there a graphhopper helloworld file that one can run that just works?

I’m trying to follow the code from here - https://www.viaboxx.de/route-optimization/distances-for-vehicle-routing-with-graphhopper/

as suggested by another thread on this forum. But, as you can see, it’s not really working out.

I see, there are typos in that code. A bracket is missing. Also one of the functions is wrong. Here is code that at least compiles:

import com.graphhopper.GraphHopper;
import com.graphhopper.routing.util.EncodingManager;

public class hello {

public static void main(String[] args) {
	System.out.println("hi");
	
	String workDir = "gh-car";
	String vehicle = "car";
	String osmFile = "berlin-latest.osm.pbf";
	
	GraphHopper graphHopper = new GraphHopper().setGraphHopperLocation(workDir) 
		    .setEncodingManager(new EncodingManager(vehicle)) 
		    .setDataReaderFile(osmFile) 
		    .forServer();

}

}

Thanks for your input. We can improve here :slight_smile:

Feel free to submit a pull request to update the documentation. We are aware of the issue in general, see https://github.com/graphhopper/graphhopper/issues/774#issuecomment-252618565

For an up to date example also have a look into the integration tests like GraphHopperIT