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

时间:2015-09-09 12:45:52

标签: java maven intellij-idea jetty multi-module

我是个新手......也许有人可以提供帮助。

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

例如:

我的模块:F-Frontend,B-Backend

现在我通过jetty启动我的前端模块,但我需要后端功能,并且还需要运行后端模块。

有可能吗?有什么想法吗?

非常感谢

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

frontend 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

1 个答案:

答案 0 :(得分:1)

Maven模块不是单独的应用程序。为了可重用性,可以使用不同的模块将应用程序的不同部分指定为不同的Jars 你真正开始的是一个应用程序(或战争等)。项目可以通过导入该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>
相关问题