0

I'm a maven newbie...maybe someone can help.

Is it possible to start a module from another?

For example:

My modules: F-Frontend, B-Backend

Now i start my frontend-module via jetty, but i need the backend functionality and need to run the backend-module too.

Is it possible? Any ideas?

Thanks a lot

PS. I'm using intelliJ

UPDATE

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

...

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

UPDATE 2 After mvn deploy backend.

 [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
NVD
  • 15
  • 5
  • You are doing yourself no favors by abbreviating the poms. Feel free to censor things (your "xxx" stuff is fine), but don't leave out the packaging, properties, dependencies, plugins, build sections (for example) – Joakim Erdfelt Sep 09 '15 at 14:11
  • Setup your frontend project pom to run the backend war as a secondary WebAppContext. [See past answer about this technique](http://stackoverflow.com/a/27191857/775715). – Joakim Erdfelt Sep 09 '15 at 14:17

1 Answers1

1

Maven modules are not separate applications. The different modules can be used for specifying different parts of an application as different Jars, for reusability.
What you really start is an application (or war, etc). Where a project may link to a submodule by importing that jar.

parent pom need to call the modules to build (and need to be ran out of the pom.xml location of the parent :

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

So do you mean import a different jar through the pom.xml?
For more information on jetty-maven-plugin
Pom.xml like:

<?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>
Danielson
  • 2,605
  • 2
  • 28
  • 51
  • actually i've tried this before, without success...i also get this error: Failed to execute goal....Failure to find com.XXXXXXX:jar:1.0-SNAPSHOT in....maybe there is a different problem....something is wrong and i can't figure it out...ps. i've already run mvn install – NVD Sep 09 '15 at 13:19
  • Then you'd need to provide more information... Like the parent pom, front-end pom, back-end pom. Do you `deploy` your projects (to Archiva, Artifactory, mvn repository)? Is it getting resolved in IntelliJ? – Danielson Sep 09 '15 at 13:22
  • there is no resolving problems with Intellij...PS. I've updated my question, now you can check my pom files.. – NVD Sep 09 '15 at 13:40
  • Shouldn't the frontend be compiled to war `war`. Can you post what maven is saying when you hit `mvn install` via the command line? – Danielson Sep 09 '15 at 13:43
  • mvn install is OK, but frontend jetty:run doesn't work...I've posted the message....take a look – NVD Sep 09 '15 at 13:50
  • Aaah... I've updated my answer to include `jetty-maven-plugin`, for more information see http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html ... Btw, you might want to force updating, using `mvn {your-phase} -U`. Since the failed snapshot is cached in your `.m2` folder (you can also delete it manually) – Danielson Sep 09 '15 at 14:04
  • Hi, I've already done this too....jetty:run works fine if I'm not trying to add the backend module as dependency... – NVD Sep 09 '15 at 14:07
  • Have you added ` front-end back-end ` to the parent? – Danielson Sep 09 '15 at 14:09
  • @Danielson might want to use a non-snapshot version for that plugin. Try [`9.3.3.v20150827`](http://search.maven.org/#artifactdetails%7Corg.eclipse.jetty%7Cjetty-maven-plugin%7C9.3.3.v20150827%7Cmaven-plugin) – Joakim Erdfelt Sep 09 '15 at 14:10
  • @NVD IntelliJ does not resolve maven projects in the maven way, or via the maven local repository, it uses the workspace to resolve intra-project project references. It doesn't even properly support all of the maven dependency scopes. – Joakim Erdfelt Sep 09 '15 at 14:14
  • @JoakimErdfelt same problem with the non-snapshot version...it must be something with the backend pom....if I remove the dependency from the frontend pom, it works fine... – NVD Sep 09 '15 at 14:14
  • @JoakimErdfelt I agree, rather not use a snapshot... Yet tried to fix the project first, tweaking is for when it works. A snapshot should work anyway, especially on such a mundane task (like `run`)... but I'd reckon the jar/war are not installed in the `.m2` dir. – Danielson Sep 09 '15 at 14:17
  • @Danielson right, there is no jar/war files in the .m2 directory – NVD Sep 09 '15 at 14:25
  • When you added the modules, like in my updated answer, then browse (using cmd, or terminal) to the location of the parent pom. Then `mvn clean install` or `mvn clean deploy`. (deploy send the war/jars to a maven repository) hereafter you should be able to run `mvn jetty:run` after browsing to the pom.xml location of the frontend (i.e. war project) – Danielson Sep 09 '15 at 14:38
  • What happens if you only try to run `mvn deploy` on the project-name-backend? Same for project-name-frontend... If error, can you post those? – Danielson Sep 09 '15 at 14:56
  • @Danielson run mvn deploy an backend gives this error: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter and mvn deploy frontend gives the same error that I've already updated in my question – NVD Sep 09 '15 at 15:06
  • I see maven.vaadin.com in your error message... I don't understand why vaadin is called... Have you ever depoyed a project? How is your /.m2/setting.xml configured? – Danielson Sep 09 '15 at 15:24
  • 1
    The problem is the backend pom-file, I know that now. I startet my frontend with another module and it works fine, everything works...jar/war etc.....Now I have to check my backend-pom-file...thank you anyway for your help... – NVD Sep 09 '15 at 15:32