我实现了两个基于maven的独立Web项目,使用Spring MVC,hibernate和Jax-RS实现.但是我的要求发生了变化,现在我需要将项目作为子项目合并到另一个项目中,这是我们的父项目.所以我使用maven multimodule配置.
<packaging>pom</packaging>
<modules>
<module>../child1</module>
<module>../child2</module>
</modules>
Run Code Online (Sandbox Code Playgroud)
<packaging>jar</packaging>
<parent>
<groupId>com.xyz.alpha</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
Run Code Online (Sandbox Code Playgroud)
<packaging>jar</packaging>
<dependency>
<groupId>com.xyz.alpha</groupId>
<artifactId>child1</artifactId>
<version>2.0.2</version>
</dependency>
<parent>
<groupId>com.xyz.alpha</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
Run Code Online (Sandbox Code Playgroud)
但我需要在java中配置项目,以便它将扫描父项的组件以及子项目和执行项目.目前我对每个项目都有单独的配置:
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { AppConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
Run Code Online (Sandbox Code Playgroud)
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.x.y")
public class AppConfig …Run Code Online (Sandbox Code Playgroud) 我正面临一个相当大的多模块maven项目.我想看看root(父)项目是如何以groupId:artifactId的形式由子项目/子项目组成的(可能有一些标识来反映层次结构).
当然我可以编写自己的插件来获得这个打印输出,但我认为必须有一些可用的架子.
我有一个多模块Maven + Spring项目.一些模块依赖于其他模块.
假设我们有一个名为services依赖于命名模块的模块persistence.
服务模块:
persistence上下文persistence模块该persistence模块定义了一些与...持久性相关的配置:数据源,JPA,事务......
它有一些依赖性来测试限于测试范围的DB(JDBC驱动程序,DBCP,H2),因为在部署应用程序时,DataSource将在容器(Tomcat)中定义并通过JNDI访问.
现在,我想在services模块的Maven测试阶段访问模块的测试范围(传递)依赖关系persistence.
所述的Maven手册(表3.1)说,通常,测试范围依赖是不可传递地.
是否有可能在多模块项目的背景下以某种方式获取它们?
如果没有什么是好的选择?(在父pom中定义测试依赖项?...)
我从GitHub(https://github.com/henrikengstrom/roygbiv)下载了多模块Scala项目,其中一个模块是Play 2.0模块.所以我可以run在每个模块上使用SBT 命令运行整个应用程序,一切正常.但是,当我添加到Play 2.0模板(index.scala.html)非英文字符并在浏览器中按F5时,我得到编译错误:
使用UTF-8解码C:\ Users ...\web\target\scala-2.9.1\src_managed\main\views\html\index.template.scala时出现IO错误请尝试使用-encoding选项指定另一个
Play 2.0模块我也使用SBT的run命令运行,而不是使用Play控制台.
我检查了源文件编码 - 它是UTF-8.还尝试了没有BOM的UTF-8.
哪里可以有问题?
使用Gradle 4.6或更高版本时,Android Gradle插件的3.1.2版不支持按需配置.
gradle按需配置在处理具有大量模块的多模块android项目时非常有用,以避免不必要的配置.
我找不到官方发行说明/文档,解释了最新的android插件不支持按需配置的原因.有没有人更好地理解为什么它不起作用,也许未来的计划是什么?(例如,这只是一个临时错误?)是否有关于此更改的官方文档?
我已经搜索了高低,但仍然无法找到这个非常烦人的问题的简单答案,
我遵循了这个很棒的指南: 带有多服务应用程序的 JWT 一切都很好,但在指南的最后,我们建议创建一个 config-service(module) ,我已经完成了。
问题是我无法覆盖 JwtConfig 类的默认配置
项目结构如下:
-config-service
| JwtConfig.java
\
| resources
\
| jwtConfig.properties
-other-service (add dependency in the pom file of the config-service)
|
someOtherclass.java (import the JwtConfig class & using @Bean to initialize )
Run Code Online (Sandbox Code Playgroud)
JwtConfig 类:
/*all the imports*/
@PropertySource(value = "classpath:jwtConfig.properties")
public class JwtConfig {
@Value("${security.jwt.uri:/auth/**}")
private String Uri;
@Value("${security.jwt.header:Authorization}")
private String header;
@Value("${security.jwt.prefix:Bearer }")
private String prefix;
@Value("${security.jwt.expiration:#{24*60*60}}")
private int expiration;
@Value("${security.jwt.secret:JwtSecretKey}")
private String secret;
//getters
Run Code Online (Sandbox Code Playgroud)
someOtherclass.java:
/*imports*/
@Configuration
@EnableWebSecurity …Run Code Online (Sandbox Code Playgroud) maven multi-module spring-boot application.properties java-11
我有多模块 Maven 项目。Acceptance -tests模块依赖于pom.xml中的api模块(为了保密,用xxx替换真实的公司名称)。我正在尝试在验收测试中从api模块导入一些类。
这是我对验收测试模块的pom.xml依赖项:
<dependency>
<artifactId>xxx-api</artifactId>
<groupId>com.xxx</groupId>
<version>${xxx.api.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
api模块由 maven单独安装和打包(mvn install、mvn package),没有任何问题。jar文件正在我的本地.m2中创建。
但是,当我尝试编译验收测试模块时,出现编译错误,指出无法导入类,因为找不到包。
这是实际的错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project xxx-acceptance-tests: Compilation failure: Compilation failure:
[ERROR] /Users/andranik_chorokhyan/mydisk/Projects/XXX/automation/xxx-project-test-automation/xxx-acceptance-tests/src/main/java/com/xxx/xxx/utilities/api/ApiPayloadUtils.java:[17,38] package com.xxx.domain.dto does not exist
[ERROR] /Users/andranik_chorokhyan/mydisk/Projects/XXX/automation/xxx-project-test-automation/xxx-acceptance-tests/src/main/java/com/xxx/xxx/utilities/api/ApiPayloadUtils.java:[18,38] package com.xxx.domain.dto does not exist
[ERROR] symbol: class MappingData
[ERROR] location: class com.xxx.utilities.api.ApiPayloadUtils
Run Code Online (Sandbox Code Playgroud)
一个更有趣的事实是 Intellij IDEA 中没有可见的错误。没有红色下划线,没有编译错误,导航到适当的导入文件没有问题。实际上,com.xxx.domain.dto包和 …
我创建了一个具有以下结构的Maven项目:
+ root-project pom.xml (pom) + sub-projectA (jar) + sub-projectB (jar)
我已完成以下步骤:
所以我显然在顶级pom.xml中有以下元素:
<modules>
<module>sub-projectA</module>
<module>sub-projectB</module>
</modules>
Run Code Online (Sandbox Code Playgroud)
最后一步是:
mvn eclipse:clean eclipse:eclipse
Run Code Online (Sandbox Code Playgroud)
现在,如果我在Eclipse中导入root项目,它似乎将我的项目视为资源,而不是像java项目.
但是,如果我导入每个子项目sub-projectA和sub-projectB,它们看起来就像java项目.
这对我来说是个大问题,因为我有更深层次的层次结构.任何帮助,将不胜感激!
类似的问题在这里.
我想从3个不同的maven模块部署一个结果WAR.战争模块完全没有冲突:
第一个有Java类和一些WEB-INF /工件
第二个只是API - 接口 - 必须已经存在于容器中或部分产生的战争中(这就是我想要的)
第三个是实现类,WEB-INF/artifacts(spring infrastructure,web.xml等)
第一个取决于接口和实现.第三个取决于接口.
我有可能的选择混乱.
我是否使用Overlays?
或者我是否使用程序集插件来集成第二个类?
我使用Cargo插件吗?
或者,如果我从不同的模块中指定webResources,它是否由maven-war-plugin完成?因为这个家伙几乎和我一样,但只有2个war模块,而且他不使用汇编插件,也不使用Overlays ....
请告诉我,这怎么做得好?
我刚刚开始使用Maven构建应用程序.我的一种方法是构建一个多模块Web应用程序.使用Eclipse可以很容易地构建这种类型的应用程序.到目前为止一切正常.我失败的地方是部署.我使用Wildfly作为我的应用程序服务器,并且表示层的部署运行良好.但是,当我想从父项目部署时,我得到以下消息:
Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) on project build: Error executing FORCE_DEPLOY: C:\Users\*****\Desktop\workspace\mvnexbook-examples-1.0\ch-multi\target\parent-0.8-SNAPSHOT.maven-project (No such file or directory)
Run Code Online (Sandbox Code Playgroud)
这非常令人困惑.部署是否不是从.m2/repository文件夹中以前安装的文件进行的?我的父文件夹中是否需要目标目录?
我的父pom文件
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>0.8-SNAPSHOT</version>
</parent>
<artifactId>simple-webapp</artifactId>
<packaging>war</packaging>
<name>Multi Chapter Simple Web Application Project</name>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.4_spec</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-weather</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>simple-webapp</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
编辑:我刚用码头试过.工作良好.为什么它不与Wildfly合作?
EDIT2:我正在使用sonatype书中的简单父项目示例
multi-module ×10
maven ×6
java ×3
android ×1
compilation ×1
dependencies ×1
eclipse ×1
gradle ×1
java-11 ×1
jboss ×1
maven-2 ×1
maven-3 ×1
pom.xml ×1
pretty-print ×1
printing ×1
sbt ×1
scala ×1
spring ×1
spring-boot ×1
spring-mvc ×1
structure ×1
unit-testing ×1
war ×1
wildfly ×1