繁体   English   中英

Maven多模块项目-从另一个模块启动模块?

[英]Maven multi module project - start module from another module?

我是一名新手,也许有人可以帮忙。

是否可以从另一个模块启动模块?

例如:

我的模块:F-前端,B-后端

现在,我通过码头启动前端模块,但是我需要后端功能,并且也需要运行后端模块。

可能吗? 有任何想法吗?

非常感谢

PS。 我正在使用intelliJ

更新

父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>

    <groupId>com.xxx.maven</groupId>
    <artifactId>project-name</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>project-name-parent</name>
...

前端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">
    <parent>
        <artifactId>project-name</artifactId>
        <groupId>com.xxx.maven</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>project-name-frontend</artifactId>
...
<dependency>
            <groupId>com.xxx.maven</groupId>
            <artifactId>project-name-backend</artifactId>
            <version>1.0-SNAPSHOT</version>
</dependency>

...

后端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">
    <parent>
        <artifactId>project-name</artifactId>
        <groupId>com.xxx.maven</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>project-name-backend</artifactId>
    <packaging>jar</packaging>
...

更新2在mvn部署后端之后。

 [WARNING] The POM for com.xxx.maven:project-name-backend:jar:1.0-SNAPSHOT is missing, no dependency information available
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.285s
    [INFO] Finished at: Wed Sep 09 15:45:13 CEST 2015
    [INFO] Final Memory: 13M/304M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project project-name-cmf-frontend: Could not resolve dependencies for project com.xxx.maven:project-name-frontend:jar:1.0-SNAPSHOT: Failure to find com.xxx.maven:project-name-backend:jar:1.0-SNAPSHOT in http://maven.vaadin.com/vaadin-addons was cached in the local repository, resolution will not be reattempted until the update interval of vaadin-addons has elapsed or updates are forced -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Maven模块不是单独的应用程序。 不同的模块可用于将应用程序的不同部分指定为不同的Jar,以实现可重用性。
您真正开始的是一个应用程序(或战争等)。 通过导入该jar,项目可以链接到子模块的位置。

父pom需要调用要构建的模块(并且需要用完父对象的pom.xml位置:

<modules>
    <module>front-end</module>
    <module>back-end</module>
</modules>

那么,您是说通过pom.xml导入其他jar吗?
有关jetty-maven-plugin的更多信息
Pom.xml像:

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>parent.project</groupId>
        <artifactId>artifact</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>group_id</groupId>
            <artifactId>artifact_id</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            ...<!-- add plugin for mvn jetty:run (check the name to match your project name) --> 
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.1-SNAPSHOT</version>
                <configuration>
                    <war>${project.basedir}/target/mycustom.war</war>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM