Search code examples
maven

maven execute java command


I want to execute a jar file with parameters from maven. The command I want to execute is listed below. I have the perf4j jar file in the dependency. The times.log file is in they filesystem.

java -jar perf4j-0.9.16.jar times.log

Thanks


Solution

  • I had looked at maven exec plugin but wasn't sure how and where to specify the jar file name, hence thanks for your responses, but I was looking at a little more info especially with jar file. With some trial and error the following worked. I had to find the main class to use from the jar file. mvn install runs the file and produces the following output:

        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <mainClass>org.perf4j.LogParser</mainClass>
                                <arguments>
                                    <argument>InlineLogging.log</argument>
                                </arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        
        <dependencies>
            <dependency>
                <groupId>org.perf4j</groupId>
                <artifactId>perf4j</artifactId>
            </dependency>
        </dependencies>