How to use Graphhopper In Java by custom Profile?

I search some use custom profile example in github ,but i can’t run the application.
Graphhopper version is 7.0.
Here is my code:

 customModel = new CustomModel();
customModel.setDistanceInfluence(90d);
 customModel.addToPriority(If("road_class == MOTORWAY", MULTIPLY, "0.1"));

   GraphHopper hopper = new GraphHopper();
        hopper.setOSMFile(dataFile.getAbsolutePath());
     
        hopper.setGraphHopperLocation(parentPath + File.separator + cacheName + File.separator);
        // see docs/core/profiles.md to learn more about profiles
Profile profile = new CustomProfile("car_custom").setCustomModel(customModel).setVehicle("car").setWeighting("custom");
   
        hopper.setProfiles(profile);
        hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car_custom"));

        // now this can take minutes if it imports or a few seconds for loading of course this is dependent on the area you import
        hopper.importOrLoad();

ERROR

java.lang.NoSuchFieldError: typeParameters
	at com.graphhopper.routing.weighting.custom.CustomModelParser.injectStatements(CustomModelParser.java:435)
	at com.graphhopper.routing.weighting.custom.CustomModelParser.access$100(CustomModelParser.java:41)
	at com.graphhopper.routing.weighting.custom.CustomModelParser$2.copyMethodDeclarator(CustomModelParser.java:418)
	at org.codehaus.janino.util.DeepCopier.copyPackageMemberClassDeclaration(DeepCopier.java:593)
	at org.codehaus.janino.util.DeepCopier$3.visitPackageMemberClassDeclaration(DeepCopier.java:207)
	at org.codehaus.janino.util.DeepCopier$3.visitPackageMemberClassDeclaration(DeepCopier.java:202)
type or paste code here

Never had this error. How do you include the external library janino? Maybe the version you use is outdated. Please ensure to use the version specified in the pom.xml (3.1.2)

I use this dependency in Java,it has include the external library janino

        <dependency>
            <groupId>com.graphhopper</groupId>
            <artifactId>graphhopper-core</artifactId>
            <version>7.0</version>
        </dependency>

Based on your ideas, I have reviewed the versions of all packages and found that,the version of “org.codehaus.janino” error,it is 3.1.0 instead of 3.1.2.
After I modify it ,it works!
Thanks you very much!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.