A_J
A_J

Reputation: 1013

Non maven jar dependencies giving error in pom.xml maven

I want to install some non maven jars in my maven project.

Step 1: I am using maven-antrun-plugin to generate jar of the non maven projects using ant(since the non-maven projects are Ant-based) in pre-package phase.

Step 2: Then I use maven-install-plugin to install the plugin to the local repository in package phase

Step 3: I also use maven-war-plugin to package all of them in a war in install phase

Also I have all the non maven projects added as dependencies in pom.xml When I run mvn-install on my project, pom gives an error: Missing artifact for non maven jars. The POM for com.non_maven:com.non_maven:jar:version is missing, no dependency information available

If the package phase is run then only the non maven jars will be installed in the repository. But it seems Maven expects all the dependencies already present in the repository. I can solve this issue by separately installing the non maven jars in the maven repository and then running pom.xml to create the war. But I want to do these steps using the single pom. How can I achieve this ? Thanks

pom.xml

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

    <groupId>com.swte.sca</groupId>
    <artifactId>MyProject</artifactId>
    <packaging>war</packaging>
    <version>1.1.19</version>
    <name>MyProject</name>

    <build>
        <finalName>MyProject</finalName>
        <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.1</version>
                <executions>
                    <execution>
                        <id>common-jar</id>
                        <phase>package</phase>
                        <configuration>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>com.non_maven</groupId>
                            <artifactId>com.non_maven</artifactId>
                            <version>${version}</version>
                            <file>F:/addressMaven</file>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
                </executions>
        </plugin>
                    <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                      <executions>
                        <execution>
                          <id>copy-war-file</id>
                          <phase>prepare-package</phase>
                          <configuration>
                                <target name="display">
                                  <ant antfile="src/main/ant/build.xml"/>
                                </target>
                          </configuration>
                          <goals>
                            <goal>run</goal>
                          </goals>
                        </execution>
                      </executions>
                </plugin>   
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <outputDirectory>F:\Folder\APP</outputDirectory>
            </configuration>
        </plugin>

        </plugins>
        <resources>
    <resource>
        <directory>src/main/resources</directory>
    </resource>
     <resource>
       <directory>F:/addressMaven</directory>
     </resource>
</resources>
    </build>


    <dependencies>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.0</version>
            <scope>provided</scope>
        </dependency>

<dependency>
    <groupId>com.swte.ojdbc7</groupId>
    <artifactId>com.swte.ojdbc7</artifactId>
    <version>${version}</version>
  </dependency>


<dependency>
    <groupId>com.non_maven</groupId>
    <artifactId>com.non_maven</artifactId>
    <version>${version}</version>
  </dependency>




    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

Upvotes: 0

Views: 204

Answers (1)

Luc
Luc

Reputation: 1433

From your pom, I can see that you are not using module. https://maven.apache.org/guides/mini/guide-multiple-modules.html

I have seen similar problems solved by modules.

You can keep your master pom for your build as it is, and you extract your specific build step in a dedicated module, with a child pom.

<version>1.1.19</version>
<name>MyProject</name>
<modules>
    <module>child-module</module>
</modules>
<build>

In the folder /child-module, you create a pom similar to your parent's one:

   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>com.swte.sca</groupId>
      <artifactId>MyProject</artifactId>
      <version>1.1.19</version>
   </parent>
   <groupId>com.swte.sca</groupId>
   <artifactId>non-maven-module</artifactId>
   <version>1.0.0</version>

And you can write there your build step for your module

Upvotes: 2

Related Questions