我在Microsoft网站上关注此tutorial以获取一个简单的发送事件到Azure事件中心以在java中工作。但是,我使用了maven并遵循了所有内容,但最终的jar文件运行时出现异常错误。请在这就是我所做的。
我在Eclipse Juno中创建了简单的Maven项目,这是我的pom.xml的内容
`<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/xsd/maven-4.0.0.xsd">
<description>Java libraries for talking to Windows Azure Event Hubs</description>
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>send</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.bd.Send</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.14.0</version>
</dependency>
</dependencies>
</project>`
这个pom.xml文件是否正确?当我运行最终的jar文件时,我得到异常错误,但项目编译正确。
如何使用maven ??
配置send event hub java项目提前致谢
答案 0 :(得分:1)
这是有效的pom.xml文件:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>send</groupId>
<artifactId>send</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>osssonatype</id>
<name>OSS Sonatype</name>
<url>https://repo1.maven.org/maven2/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.14.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>sdasf.Send</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
运行Maven安装时。在目标文件夹内将有2个jar文件。运行具有依赖项的那个解决了我的问题。
cmd命令行上的:
java -jar send-0.0.1-SNAPSHOT-jar-with-dependencies.jar