我正在尝试构建一个alexa-app,其中一些注释驱动了依赖注入(dagger 2)代码。 alexa-sample-skills-test给出了示例pom,并指示使用以下命令构建具有依赖关系的jar。
mvn assembly:assembly -DdescriptorId=jar-with-dependencies package
使用上述内容的构建失败,并在此link中列出了异常和输出。稍微深入研究maven docs后,我发现程序集:程序集目标使用的非标准构建过程可能会造成严重破坏。相反,maven assembly-plugin doc建议使用程序集:单个目标。因此,我使用以下命令:
mvn assembly:single -DdescriptorId=jar-with-dependencies package
Voila ..代码编译和链接很顺利。我得到一个[project-name] -jar-with-dependencies.jar文件。但是,当我在亚马逊服务器上传jar并尝试测试技能时,测试失败。日志说无法找到类:echo.client.AccountInfoStreamHandler(ClassNotFoundException)。我想这个类恰好发生在根启动器类中。
现在,我将所有匕首2依赖关系核化,并用最简单的代码库重复相同的操作。第一个maven命令(assembly:assembly)有效。第二个maven命令(程序集:单个)失败并出现相同的“ClassNotFoundException”错误。我究竟做错了什么?我对maven不太熟悉,这是我第一次尝试解决maven命令问题。任何建议,指示,建议都非常感谢。
对于参考,POM文件如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.apil.echo.accountant</groupId>
<artifactId>echo-device-client</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>Echo Device Client</name>
<repositories>
<repository>
<id>alexa-skills-kit-repo</id>
<url>file://${project.basedir}/repo</url>
</repository>
<repository>
<id>Maven Central</id>
<url>http://repo1.maven.org/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.plaid</groupId>
<artifactId>plaid-java</artifactId>
<version>0.2.12</version>
</dependency>
<dependency>
<groupId>alexa-skills-kit</groupId>
<artifactId>alexa-skills-kit</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.0.6.v20130930</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.0.6.v20130930</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.9.40</version>
</dependency>
<!-- using mockito for test -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.0</version>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
<property name="disableRequestSignatureCheck" value="false"/>
<property name="supportedApplicationIds" value=""/>
<property name="timestampTolerance" value="150"/>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>Launcher</mainClass>
<systemProperties>
<systemProperty>
<key>javax.net.ssl.keyStore</key>
<value>/insert/your/path/java-keystore.jks</value>
</systemProperty>
<systemProperty>
<key>javax.net.ssl.keyStorePassword</key>
<value>insert_your_password</value>
</systemProperty>
<systemProperty>
<key>com.amazon.speech.speechlet.servlet.disableRequestSignatureCheck</key>
<value>${disableRequestSignatureCheck}</value>
</systemProperty>
<systemProperty>
<key>com.amazon.speech.speechlet.servlet.supportedApplicationIds</key>
<value>${supportedApplicationIds}</value>
</systemProperty>
<systemProperty>
<key>com.amazon.speech.speechlet.servlet.timestampTolerance</key>
<value>${timestampTolerance}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
答案 0 :(得分:0)
我使用最近为alexa-sample-skills-test提供的gradle构建脚本结束了。初步构建检查显示所需的类:echo.client。[Class ..]确实存在于生成的构建中。
检查由上述maven命令产生的超级罐子,我注意到了
mvn assembly:assembly ...
导致一个jar包含了缺少类的echo.client包。但是,
mvn assembly:single...
导致jar没有echo.client包,或者包中定义的任何应用程序类。因此,我得到了ClassNotFoundException。我仍然无法弄清楚为什么会这样。但是,我认为现在是时候切换到&#39; gradle&#39;从这一点开始......