'Maven: How to fix foreign imports? (in Azure Function)
when I try to start my Azure function locally in Visual Studio Code I get a Maven error as following:
[ERROR] Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.13.0:package (package-functions) on project ShapefileReader: Execution package-functions of
goal com.microsoft.azure:azure-functions-maven-plugin:1.13.0:package failed: A required class was missing while executing com.microsoft.azure:azure-functions-maven-plugin:1.13.0:package: com/vividsolutions/jts/geom/Geometry
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>com.microsoft.azure:azure-functions-maven-plugin:1.13.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/[user]/.m2/repository/com/microsoft/azure/azure-functions-maven-plugin/1.13.0/azure-functions-maven-plugin-1.13.0.jar
[ERROR] urls[1] = file:/C:/Users/[user]/.m2/repository/com/squareup/okhttp3/okhttp/4.9.1/okhttp-4.9.1.jar
...
[ERROR] urls[201] = file:/C:/Users/[user]/.m2/repository/org/javassist/javassist/3.26.0-GA/javassist-3.26.0-GA.jar
[ERROR] urls[202] = file:/C:/Users/[user]/.m2/repository/com/github/zafarkhaja/java-semver/0.9.0/java-semver-0.9.0.jar
[ERROR] urls[203] = file:/C:/Users/[user]/.m2/repository/org/jacoco/org.jacoco.agent/0.8.7/org.jacoco.agent-0.8.7-runtime.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR] : com.vividsolutions.jts.geom.Geometry
Running the task as "mvn clean package -e" additionally gives me the ClassNotFoundException:
Caused by: java.lang.ClassNotFoundException: com.vividsolutions.jts.geom.Geometry
at java.net.URLClassLoader.findClass (URLClassLoader.java:471)
at java.lang.ClassLoader.loadClass (ClassLoader.java:589)
at java.lang.ClassLoader.loadClass (ClassLoader.java:522)
at java.lang.Class.getDeclaredMethods0 (Native Method)
at java.lang.Class.privateGetDeclaredMethods (Class.java:3166)
at java.lang.Class.getDeclaredMethod (Class.java:2473)
at org.reflections.util.Utils.getMemberFromDescriptor (Utils.java:75)
at org.reflections.util.Utils.getMethodsFromDescriptors (Utils.java:88)
at org.reflections.Reflections.getMethodsAnnotatedWith (Reflections.java:478)
at com.microsoft.azure.toolkit.lib.legacy.function.handlers.AnnotationHandlerImpl.findFunctions (AnnotationHandlerImpl.java:52)
at com.microsoft.azure.maven.function.PackageMojo.findAnnotatedMethods (PackageMojo.java:175)
at com.microsoft.azure.maven.function.PackageMojo.doExecute (PackageMojo.java:117)
at com.microsoft.azure.maven.AbstractAzureMojo.execute (AbstractAzureMojo.java:499)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
The dependency is in my Maven folder as normally and I can also view the class com.vividsolutions.jt.geom.Geometry in Visual Studio Code so I don't think that it should appear missing. I already tried deleting the dependency from the Maven directory and redownloading it but this did not seem to change anything.
Thanks in advance!
Solution 1:[1]
For anyone looking for a possible solution com.vividsolutions.jts
has been moved to org.locationtech.jts
. Thus you should provide the jar to your maven build instead of trying to download it from maven repository.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alessio Cruciani |