我有一个多 Maven 项目设置,您可以在下面找到我的 poms 和我的 Main 类:
Maven项目结构:
家长
-- pom.xml
-- 网络
----- pom.xml
父pom:
...
<modules>
<module>web</module>
</modules>
<packaging>pom</packaging>
...
Web 模块 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>
<parent>
<artifactId>amazon-fba</artifactId>
<groupId>de.domain</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<artifactId>web</artifactId>
<dependencies>
<!-- Provided -->
<!-- Java EE 7 dependency -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>logging</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jsf</artifactId>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>ejb</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jpa</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>infinispan</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jaxrs-jsonp</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>h2</artifactId>
<version>2016.11.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<configuration>
<mainClass>de.package.Main</mainClass>
</configuration>
<executions>
<execution>
<id>package</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我的主要课程:
public class Main {
private static final String WEBAPP_SRC = "web/src/main/webapp";
public static void main(String[] args) throws Exception {
Swarm swarm = new Swarm(args);
swarm = buildSwarmFractions(swarm);
WARArchive warArchive = buildDeployment();
swarm.start()
.deploy(warArchive);
}
private static Swarm buildSwarmFractions(Swarm swarm) {
return swarm
.fraction(new DatasourcesFraction()
.dataSource(new DataSource(...)
.connectionUrl(...)
.driverName(...)
.userName(...)
.password(...)));
}
private static WARArchive buildDeployment() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL persistenceFile = classLoader.getResource("META-INF/persistence.xml");
return ShrinkWrap.create(WARArchive.class)
.addAsResource(new File(persistenceFile.toURI()), "META-INF/persistence.xml")
.addAllDependencies()
.addPackages(true, "de.mypackage")
.merge(ShrinkWrap.create(GenericArchive.class)
.as(ExplodedImporter.class)
.importDirectory(WEBAPP_SRC).as(GenericArchive.class), "/", Filters.includeAll());
}
}
我可以毫无问题地从 IntelliJ 运行 Main 类。我在父文件夹和 web 文件夹中尝试了几个 maven 命令。但是,我无法生成 -swarm.jar (Uberjar)。我尝试了不同的包装(jar/war)但没有成功。我想要实现的是:
- 能够从 IntelliJ 运行 Main 方法
- 生成一个我可以调用的 Uberjar (java -jar)
WildFly Swarm 文档指出,运行 mvn 包应该会生成 uberjar。我在文档中缺少什么吗?
任何帮助表示赞赏。