0

My hope was that it would be easy to get Maven to run our application on any machine by simply deploying the pom.xml and using the maven exec goal.

The main class to run is inside the jar which is produced from the same pom.xml. But it seems that, while Maven quite nicely includes all the dependencies on the classpath, the pom's jar does not get included, or else it cannot be resolved from the repository where maven deployed it (which is an internal not public repository).

The steps I followed:

  1. run mvn deploy -- this deploys our jar on an internal maven repository
  2. install maven on the target machine (not the same as the build machine)
  3. deploy the pom.xml to the target machine.
  4. try to run using mvn exec:java ... or mvn exec:exec ...

What I see is that Maven pulls all the dependency jars onto the classpath correctly, but does not pull in the jar described by the pom.xml.

I tried various configuration options in the pom.xml, but nothing seemed to work. First, tried to configure exec:java as shown in this answer, but Maven did not search the internal repository for that jar. (It did seem to check the public maven repositories though).

Second, I tried to switch to the exec:exec version and configure like this:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.4.0</version>

            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-classpath</argument>
                    <classpath/>
                    <argument>com.ezxinc.tfix.TFix</argument>                       
                </arguments>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>ezxinc</groupId>
                    <artifactId>tfix</artifactId>
                    <version>0.0.3-SNAPSHOT</version>
                    <type>jar</type>
                </dependency>
            </dependencies>
        </plugin>

The dependency shown there is the information for the jar which the pom.xml deployed into our internal repository.

Of course, everything works fine if I unjar the class files into target subdirectory beneath the one where the pom.xml is.

If it helps, the full pom.xml can viewed here.

Community
  • 1
  • 1
Sam Goldberg
  • 6,711
  • 8
  • 52
  • 85

1 Answers1

1

I think you'll need to have a different pom.xml file rather than trying to use the same pom from the project being built in step 1 of your description. This separate pom file could then include the project in question as a dependency so that it will get downloaded and included in the classpath when running maven commands.

The problem is that maven assumes that the project being described by a pom file is going to be compiled form source rather than downloaded from a repository. Anything you want downloaded from a repository needs to be a dependency, and if you try to include the current project as a dependency of itself you end up with a problem where the project could never be built the first time since it hasn't already been built and deployed to the repository yet.

neuronaut
  • 2,689
  • 18
  • 24