我有一个多maven项目设置,下面你可以找到我的poms和我的Main类:
Maven项目结构:
父
- pom.xml
- 网站
----- pom.xml
家长pom:
...
<modules>
<module>web</module>
</modules>
<packaging>pom</packaging>
...
网络模块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)但没有成功。我想要实现的是:
WildFly Swarm文档指出,运行mvn包应该生成uberjar。文档中是否有任何遗漏?
感谢任何帮助。
答案 0 :(得分:1)
-swarm.jar没有生成,因为我在web / pom.xml中执行错误
<build>
<finalName>web</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<configuration>
<mainClass>de.kevcodez.amazonfba.Main</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
更改后,我还必须更改我的Main类才能正确部署。这是我的主要班级:
public static void main(String[] args) throws Exception {
Swarm swarm = new Swarm(args);
swarm = buildSwarmFractions(swarm);
WebArchive webArchive = ShrinkWrap.createFromZipFile(WebArchive.class, new File("web/target/web.war"));
swarm.start()
.deploy(webArchive);
}
private static Swarm buildSwarmFractions(Swarm swarm) {
return swarm
.fraction(new DatasourcesFraction()
.dataSource(...));
}