[英]How can I build a release with embedded jetty and maven?
我正在嘗試配置maven來構建一個可運行的jar。 這個項目包含幾個依賴項以及嵌入式jetty。
我想嵌入所有依賴項(有效)並擁有一個可執行jar。 我可以從eclipse運行項目,但是一旦我嘗試運行jar,我就會在org.eclipse.jetty.servlet.ServletContextHandler上獲得ClassNotFoundExceptions。
但是,當我使用maven-plugin並運行exec:java時,程序啟動沒有問題。
我究竟做錯了什么?
這是我的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>comms</groupId>
<artifactId>comms-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Air</name>
<properties>
<jettyVersion>9.2.7.v20150116</jettyVersion>
<gsonVersion>2.3.1</gsonVersion>
<logjVersion>2.1</logjVersion>
<lombokVersion>1.16.2</lombokVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gsonVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${logjVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${logjVersion}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombokVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals><goal>java</goal></goals>
</execution>
</executions>
<configuration>
<mainClass>comms.Loader</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<mainClass>comms.Loader</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
我注意到你將jetty-maven-plugin聲明為依賴項 ,而不是插件聲明。 jetty-maven-plugin依賴於Jetty,而且(即對Jetty的傳遞依賴性)是Jetty類如何被拉入Maven類路徑。
但是,該依賴項被聲明為“提供”,它基本上表示:“我的代碼依賴於此,但通常它將由部署環境提供”。 Maven會引入依賴,因為它需要它來構建你的源代碼(這可能是exec插件工作的原因),但是不會把它包含在你的jar中, 因為你特意告訴它這樣做 。
在我看來,你的pom根本不反映情況:
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.