-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext when building a function which calls Spring's Application Context #90
Comments
Reproducer.zip |
I was able to get around this by declaring all my dependencies in the tag. However seems a bit awkward having to declare the dependencies twice: com.microsoft.azure azure-functions-maven-plugin java-functions-group ${functionAppName} ${functionAppRegion} FUNCTIONS_EXTENSION_VERSION beta package-functions package
|
Hi @damadei , sorry for the late reply. Could you please explain more about |
Hi, The maven Pom attached is the one that presents the error so it does not declared the dependencies twice. What I said is that to get rid of the issue I redeclared all dependencies again inside the plugin section for the azure functions plugin, this way it worked fine. |
Yes I can reproduce the bug. It looks like something wrong with the classpath happened when we use the reflection to find the method with Except duplicate the dependencies, another work around could be adding the maven shaded plugin into the pom file: <build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
...
</plugins>
</build> And please put the shaded plugin in the first place of the field to make sure the shaded jar will be packaged at the first time. After we find out a way to fix the classpath issue, we will inform you in this issue thread. 😄 |
+1 also encounter this issue, and the shade workaround does not work 👎 |
Updated the code and I think the problem should be resolved. The change has not been released, but you can install the code into your local machine to check if the problem is resolved. Really appreciated if you can help to verify. Steps: Install plugin
Update the pom.xml@damadei take your pom file as an example: <build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>0.1.10-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<configuration>
<resourceGroup>java-functions-group</resourceGroup>
<appName>${functionAppName}</appName>
<region>${functionAppRegion}</region>
<appSettings>
<property>
<name>FUNCTIONS_EXTENSION_VERSION</name>
<value>beta</value>
</property>
</appSettings>
</configuration>
<executions>
<execution>
<id>package-functions</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.build.directory}/azure-functions/${functionAppName}
</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>host.json</include>
<include>local.settings.json</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/azure-functions/${functionAppName}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> In short, what we changed in the pom file:
More explanationRecently, the Azure Java Function support to upload a In the plugin side, we add the |
Hi, thanks for getting back so fast! I've tried to follow the above instructions and encountered some issues
so the maven command line needed is:
Once this was completed, I did as described above and set the version of the plugin to 0.1.10-SNAPSHOT, removed the maven-assembly plugin and removed the dependencies from the azure-functions-plugin configuration, but I still encounter:
Interestingly, the jar that contains that class (corda-api) is not on the list of scanned jars. Adding the list of dependencies back to the plugin configuration does work. |
@roastario Did you add the maven-dependency-plugin in your pom? <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/azure-functions/${functionAppName}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin> |
Sorry, I'm travelling today. When I arrive I will push to GitHub the
project I am building so that you can see the pom!
…On Thu, 22 Mar 2018, 10:04 Sheng Chen, ***@***.***> wrote:
@roastario <https://github.com/roastario> Did you add the
maven-dependency-plugin in your pom?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/azure-functions/${functionAppName}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACtkPnP5MuEeoYu87utOmaaQEhpm3ZuBks5tg3c2gaJpZM4SP88q>
.
|
@roastario Great! Thanks. |
hokay @jdneo I've pushed it to: https://github.com/roastario/azure-functions-networkmap and it's on branch "new_plugins_investigation" feel free to check it out and test it! |
@roastario I tested your code, and no error occurred during the package lifecycle. I also tested to package after removing all the dependencies definition in the azure-functions-maven-plugin configuration, also works well. Does the problem still occur on your side? |
Hi, I must apologize, I just tried it again with removing the second list of dependencies and it worked. I must have had something odd in my environment. Looks like it's fixed, thanks 👍 |
@roastario Thank you too to share the project to me and help verify the issue. 😄 I'll inform you in this issue thread once we released this fix into the Maven Central. |
v0.2.0 released. Please have a try! |
Plugin name and version
com.microsoft.azure.azure-functions-maven-plugin:0.1.10
Plugin configuration in your
pom.xml
Expected behavior
Generate my maven package
Actual behavior
I'm getting the error bellow only when my code is using applicationContext.getBean() method. If I use ApplicationContext class, it works.
So it works with this:
ApplicationContext appContext = new ClassPathXmlApplicationContext("classpath*:/application-context.xml");
If I add the following line, it stops working:
appContext.getBean("jdbcTemplate");
And the mvn clean package throws the following error:
Number of foreign imports: 1
import: Entry[import from realm ClassRealm[maven.api, parent: null]]
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethod(Class.java:2128)
at org.reflections.util.Utils.getMemberFromDescriptor(Utils.java:88)
at org.reflections.util.Utils.getMethodsFromDescriptors(Utils.java:101)
at org.reflections.Reflections.getMethodsAnnotatedWith(Reflections.java:482)
at com.microsoft.azure.maven.function.handlers.AnnotationHandlerImpl.findFunctions(AnnotationHandlerImpl.java:43)
at com.microsoft.azure.maven.function.PackageMojo.findAnnotatedMethods(PackageMojo.java:97)
at com.microsoft.azure.maven.function.PackageMojo.doExecute(PackageMojo.java:62)
at com.microsoft.azure.maven.AbstractAzureMojo.execute(AbstractAzureMojo.java:288)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 32 more
Steps to reproduce the problem
The text was updated successfully, but these errors were encountered: