Graphhopper编译报MojoFailureException及运行配置问题求助
Hey there! Let's tackle these GraphHopper issues one by one—since you're new to the project and its environment, I'll break this down into clear, actionable steps to get you up and running.
That MojoFailureException usually points to a Maven-related hiccup during the build process. Here's what you can try:
Verify your Maven and JDK versions: GraphHopper requires Java 11+ and Maven 3.6+. Run these commands in bash to check:
java -version mvn -vIf your versions are outdated, update them first—this is a super common root cause for build failures.
Clean and rebuild with skipped tests: Sometimes cached build files or failing tests block the core module compilation. Run this command to skip tests temporarily and get the core module built:
mvn clean install -DskipTestsThis will wipe old build artifacts, download any missing dependencies, and compile all modules without running tests (you can run tests later once the core is working).
Fix corrupted Maven dependencies: If the error mentions missing or corrupted dependencies, delete the problematic folder in your local Maven repository (usually at
~/.m2/repository/com/graphhopper) and re-run the build command above. Maven will re-download fresh, uncorrupted dependencies.
Running graphhopper.sh directly in IntelliJ isn't the right approach—let's set up the project properly:
Import the project as a Maven project: Open IntelliJ, go to
File > Open, and select thepom.xmlfile in the root of your cloned GraphHopper repository. Let IntelliJ finish importing all Maven dependencies (this might take a minute, depending on your internet speed).Run the core application via Java main class: Instead of the shell script, run the Java main class directly:
- Open the Maven panel on the right side of IntelliJ.
- Navigate to
graphhopper > core > Plugins > spring-boot > spring-boot:run—click this to start the GraphHopper web service. - Alternatively, create a custom Run Configuration: Go to
Run > Edit Configurations, add a newApplicationconfiguration, set the main class tocom.graphhopper.application.GraphHopperApplication, and add VM options like-Xmx4g(to give the app enough memory for graph processing).
Set build targets correctly: If you just need to compile the core module, in the Maven panel, right-click the
coremodule and selectCleanthenInstall. This does the same as the bash command but within IntelliJ's interface.Fix dependency issues: If you see red underlines for dependencies, click the
Reload All Maven Projectsbutton in the Maven panel (the circular arrow icon) to refresh dependencies. Also, check your project's JDK setup: Go toFile > Project Structure > Projectand ensure the SDK is set to Java 11 or higher.
内容的提问来源于stack exchange,提问作者marpec

