我正在尝试将一个多模块的项目转化为野蝇群。然而,我不知道如何正确地设置它。
当我从核心目录运行mvn wildfly-swarm:run时,它启动服务器,一个错误表示它找不到我的持久性单元。persistence.xml在DBlayer模块中,所以这是有意义的。
我试图从根目录运行它,但它说插件群没有定义。因此,我尝试在root pom.xml中定义插件,而不是在core模块pom.xml中定义插件,但是不能创建-swarm.jar。
那我该怎么安排呢?
这是我的根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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx</groupId>
<artifactId>x</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<version.wildfly.swarm>1.0.0.Final</version.wildfly.swarm>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>bom</artifactId>
<version>${version.wildfly.swarm}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>backgroundServices</module>
<module>core</module>
<module>DBLayer</module>
<module>userArea</module>
</modules>
<dependencies>
<!-- Java EE 7 dependency -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- Wildfly Swarm Fractions -->
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jpa-mysql</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jsf</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>keycloak</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>logging</artifactId>
</dependency>
</dependencies>
</project>然后我添加到core.xml中:
<build>
<plugins>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>核心pom:
<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">
<parent>
<groupId>xxx</groupId>
<artifactId>x</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>xxx</groupId>
<artifactId>DBLayer</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>xxx</groupId>
<artifactId>backgroundServices</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>DBlayer pom:
<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">
<parent>
<groupId>xxx</groupId>
<artifactId>x</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>DBLayer</artifactId>
</project>不过,我没有指定任何主要方法。我只有一个persistence.xml在DBLayer下面:
DBLayer/src/main/resources/META
所以我假设蜂群会自动定义驱动程序和数据源。我的意思是,在通配符中,您必须在standalone.xml中定义驱动程序和数据源。我什么也没做,也许这就是问题所在。然而,在他们的例子中,他们也不这样做。https://github.com/wildfly-swarm/wildfly-swarm-examples/blob/master/jpa/jpa-war/src/main/resources/META-INF/persistence.xml
这是我的持久性单元:
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="my-pu" transaction-type="JTA">
<jta-data-source>java:/walbangDbDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>
<properties>
<!--<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>-->
<!--<property name="javax.persistence.sql-load-script-source" value="sql_scripts/loading_script.sql"/>-->
<property name="hibernate.enable_lazy_load_no_trans" value="true"/>
</properties>
</persistence-unit>
</persistence>发布于 2016-07-03 18:20:00
在多模块Maven项目中,请记住直接从根POM启动Maven命令。
首先,将wildfly-swarm-plugin声明保存在WAR模块中,将其放在其他地方是不合适的,因为它适用于WAR项目。然后,您需要安装模块DBLayer,以便模块core (这是您的WAR)能够看到它(因此,可以看到它的persistence.xml)。最后,您需要确保只在WAR模块中使用wildfly-swarm:run命令行开关调用目标-pl。
因此,从根POM调用命令:
mvn clean install && mvn -pl core wildfly-swarm:run这将正确地构建您的多模块项目,并运行WAR与野生苍蝇群插件。您可以找到这样一个设置关于这个GitHub回购的工作示例。
https://stackoverflow.com/questions/38172358
复制相似问题