0
votes

I'm getting the following error while trying to change property file content using antrun plugin from maven pom.xml file:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (ant-create-properties
-file-content) on project SROTest: An Ant BuildException has occured: Problem: failed to create task or ty
pe propertyfile
[ERROR] Cause: the class org.apache.tools.ant.taskdefs.optional.PropertyFile was not found.
[ERROR]         This looks like one of Ant's optional components.
[ERROR] Action: Check that the appropriate optional JAR exists in
[ERROR]         -ANT_HOME\lib
[ERROR]         -the IDE Ant configuration dialogs
[ERROR]
[ERROR] Do not panic, this is a common problem.
[ERROR] The commonest cause is a missing JAR.
[ERROR]
[ERROR] This is not a bug; it is a configuration problem
[ERROR]
[ERROR] -> [Help 1]

here is my pom.xml file:

<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.mycompany</groupId>
    <artifactId>Test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <suiteFile></suiteFile>
    </properties>



    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl -->
        <dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.6.12</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.1</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxp-api</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant-junit</artifactId>
            <version>1.6.5</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>ant-create-properties-file-content</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>


                            <tasks>
                                    
                                <propertyfile file="test.properties">
                                    <entry key="browser" value="chrome"/>
                                    <entry key="run_on_grid" value="true"/>
                                    <entry key="hub_address" value="selenium-hub.service.mycompany.mgmt"/>
                                    <entry key="take_screenshots_on" value="true"/>
                                    <entry key="highlight_on" value="true"/>
                                    <entry key="recording_video_on" value="false"/>
                                    <entry key="run_with_KLB" value="false"/>
                                    <entry key="sut_url" value="http://aaa/weblink400/1/backoffice.app?noplugin=1"/>
                                </propertyfile>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

this script goal is to change properties file content, when executing it using ant build.xml file and ant command (cmd command) it's work as expected, but when trying to execute it using maven command. I got the failure shown above.

1
First of all, there is no Maven4 ;-) . You probably use Maven 3.x. Secondly, the error says that you are probably missing a jar for your ant tasks. Often, the ant run plugin requires additional dependencies to run the ant tasks. - J Fabian Meier
how can add the dependency to the ant task, I need this : <dependency> <groupId>ant</groupId> <artifactId>ant-junit</artifactId> <version>1.6.5</version> </dependency> - Ali Taha

1 Answers

1
votes

Put the dependency as <dependency> under <plugin>.

this how it should be:

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>ant</groupId>
                        <artifactId>optional</artifactId>
                        <version>1.5.4</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>ant-create-properties-file-content</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                                <tasks>
                                <propertyfile file="test.properties">
                                    <entry key="browser" value="chrome"/>
                                    <entry key="run_on_grid" value="true"/>
                                    <entry key="hub_address" value="selenium-hub.service.mycompany.mgmt"/>
                                    <entry key="take_screenshots_on" value="true"/>
                                    <entry key="highlight_on" value="true"/>
                                    <entry key="recording_video_on" value="false"/>
                                    <entry key="run_with_KLB" value="false"/>
                                    <entry key="sut_url" value="http://aaa/weblink400/1/backoffice.app?noplugin=1"/>
                                </propertyfile>
                            
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>