1

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

4 Answers 4

3

You might want to take a look @ exec-maven-plugin

Sign up to request clarification or add additional context in comments.

2 Comments

where do i specify the jar file and the -jar option
From your description, I suspect you need it to run in a separate VM. Thus, you will need to use the exec:exec goal and specify "java" as the executable, passing the jar file and the rest of the parameters as arguments. All parameters that the exec plugin provides are described here: mojo.codehaus.org/exec-maven-plugin/exec-mojo.html
1

first

mvn clean install

than

mvn exec:java -Dexec.mainClass="com.java.App" -Dexec.args="Args"

Comments

0

What do you really want to do ? Using a jar (which is a dependency) to monitor your app ?

Did you took a look at maven exec plugin ?

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
          <execution>
            ...
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <executable>maven</executable>
          <!-- optional -->
          <workingDirectory>/tmp</workingDirectory>
          <arguments>
            <argument>-X</argument>
            <argument>myproject:dist</argument>
            ...
          </arguments>
        </configuration>
      </plugin>
    </plugins>
  </build>
   ...
</project>

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.