Mee*_*ott 7 java selenium maven aws-lambda
这是一个奇怪的错误。在将硒依赖项添加到我的maven项目的pom并将其上传到lambda之后,它说无法解压缩文件。但是,在删除依赖项之后,lambda能够很好地解压缩文件(但是它附带了后来未找到的类)。我尝试过一个一个地删除依赖项,但每个依赖项都会触发错误。
关于如何解决这个问题的任何想法?
找不到类错误
org/openqa/selenium/WebDriver: java.lang.NoClassDefFoundError
java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
Run Code Online (Sandbox Code Playgroud)
Lambda无法压缩错误
Calling the invoke API action failed with this message: Lambda was not able to unzip the file
Run Code Online (Sandbox Code Playgroud)
导致问题的依赖项
<dependency>
<groupId>org.seleniumhq.webdriver</groupId>
<artifactId>webdriver-common</artifactId>
<version>0.9.7376</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
更新的依赖关系(对于Vishal)
<dependency>
<groupId>org.seleniumhq.webdriver</groupId>
<artifactId>webdriver-common</artifactId>
<version>0.9.7376</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>2.0rc2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.141.59</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
组态
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
阴影插件将所有依赖项与开发的代码结合在一起,并将它们放入一个 Uber JAR 中。缺点是它可以覆盖资源文件,并且不能很好地处理签名的 jar(至少根据我的经验)。
如果可能的话,我建议远离阴影插件。
也就是说,如果您必须使用它 - 您的问题可能是组合 jar 资源。您可以使用许多转换器来解决此问题,并且您需要研究真正需要哪一个。我会从这样的事情开始
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>${executable.classifier}</shadedClassifierName>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>fully.qualified.ClassName</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到有关 Apache 插件的更多变压器
我建议的替代方案是 Spring Boot,它使用 Jar-in-Jar 结构和自定义 ClassLoader 从内部 jar 加载类。
这是更简单的方法,因为不必像 Shade 插件方法那样重新编写文件,并且它可以更好地处理依赖关系。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.6.RELEASE</version>
<configuration>
<classifier>${executable.classifier}</classifier>
<layout>ZIP</layout>
<mainClass>fully.qualified.ClassName</mainClass>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
说真的,看看更简单的配置!
注意:其中大部分来自我自己的笔记 - 版本号可能有点旧......
| 归档时间: |
|
| 查看次数: |
176 次 |
| 最近记录: |