在 Maven 中生成具有依赖项和测试的 jar 文件项目结构程序集描述符马文·波姆脚本
我在pom.xml中使用此代码来创建一个jar文件。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/log4j.properties</exclude>
</excludes>
<archive>
<manifest>
<mainClass>test.LeanFTest</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
我收到错误消息:
部署失败:未在 POM 内部分发中指定存储库元素
更新:
我在pom中添加了另一个插件.xml。
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>test.LeanFTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
它生成一个 jar 文件,但似乎没有依赖项。
线程 “main” java.lang.NoClassDefFoundError 中的异常:org/apache/log4j/Logger
项目结构:
C:.
├───.idea
│ └───libraries
├───META-INF
├───out
│ └───artifacts
│ └───Test_LeanFT_jar
├───resources
│ ├───leanftjar
│ └───META-INF
├───RunResults
│ └───Resources
│ ├───Snapshots
│ └───User
├───src
│ ├───main
│ │ ├───java
│ │ │ ├───com
│ │ │ │ └───myproj
│ │ │ ├───jar
│ │ │ │ └───META-INF
│ │ │ ├───META-INF
│ │ │ ├───unittesting
│ │ │ └───utils
│ │ └───resources
│ └───test
│ └───java
│ └───test
├───target
│ ├───classes
│ │ ├───com
│ │ │ └───myproj
│ │ ├───unittesting
│ │ └───utils
│ ├───generated-sources
│ │ └───annotations
│ ├───generated-test-sources
│ │ └───test-annotations
│ ├───maven-archiver
│ ├───maven-status
│ │ └───maven-compiler-plugin
│ │ ├───compile
│ │ │ └───default-compile
│ │ └───testCompile
│ │ └───default-testCompile
│ ├───surefire
│ ├───surefire-reports
│ │ ├───Command line suite
│ │ ├───junitreports
│ │ └───old
│ │ └───Command line suite
│ └───test-classes
│ └───test
└───test-output
├───All Test Suite
├───junitreports
├───My_Suite
└───old
├───All Test Suite
└───My_Suite
pom.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<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>groupId</groupId>
<artifactId>LeanFT</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Mytest</name>
<description>Regression test</description>
<properties>
<leanftsdk>C:/Program Files (x86)/HPE/Unified Functional Testing/SDK/Java/</leanftsdk>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.hp.lft</groupId>
<artifactId>sdk</artifactId>
<version>14.0.0</version>
<scope>system</scope>
<systemPath>${leanftsdk}/com.hp.lft.sdk-standalone.jar</systemPath>
</dependency>
<dependency>
<groupId>com.hp.lft</groupId>
<artifactId>report</artifactId>
<version>14.0.0</version>
<scope>system</scope>
<systemPath>${leanftsdk}/com.hp.lft.report.jar</systemPath>
</dependency>
<dependency>
<groupId>com.hp.lft</groupId>
<artifactId>unittesting</artifactId>
<version>14.0.0</version>
<scope>system</scope>
<systemPath>${leanftsdk}/com.hp.lft.unittesting.jar</systemPath>
</dependency>
<dependency>
<groupId>com.hp.lft</groupId>
<artifactId>verifications</artifactId>
<version>14.0.0</version>
<scope>system</scope>
<systemPath>${leanftsdk}/com.hp.lft.verifications.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>appmodels</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>test.LeanFTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>