0

I am working in Eclipse.

My Maven program has a pom.xml file with the exec plugin :

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>${maven.exec.plugin.version}</version>
    <configuration>
        <arguments>
            <argument>src/test/resources/file.txt</argument>
        </arguments>
        <executable>mvn</executable>
        <mainClass>${main.class}</mainClass>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I've attempted to pass an argument, but I continue to get the error:

Unknown lifecycle phase ".\src\test\resources\file.txt". You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

I have also tried to pass the file via the command line arguments found in Eclipse via Run As -> Run Configurations. I receive the same error message.

How can I pass an input file argument to the application?

  • Possible duplicate of [Maven Run Project](https://stackoverflow.com/questions/1089285/maven-run-project) – Joe Nov 06 '19 at 11:48
  • @Joe I've consulted that post. I'm still getting the error message. – Belteshazzar89 Nov 06 '19 at 11:58
  • 1
    Are you trying to run `mvn` from inside maven? It looks like the effective command you are trying to run is `mvn .\src\test\resources\file.txt`, and that's not a valid mvn command line. What exactly are you trying to run? – RealSkeptic Nov 06 '19 at 12:10
  • I'm trying to execute the program. How do I do that? Inside the Eclipse run options, I have the goal exec:exec – Belteshazzar89 Nov 06 '19 at 12:45
  • That example uses `exec:java` to run `mainClass`, but you're using `exec:exec` to run an `executable`; copy it more closely to avoid that error. – Joe Nov 06 '19 at 12:49
  • 1
    @Joe Your comment made me realize the difference between exec:exec and exec:java. In my case I do indeed want exec:java. I changed the goal in the Run Configurations to exec:java, and it worked. I was able to strip out the ```executable``` and ```executions``` tags from my pom.xml. It is now working. If you create an answer to this effect, I will mark it correct. – Belteshazzar89 Nov 06 '19 at 12:57
  • First question: Why would you like to execute maven within a Maven project? – khmarbaise Nov 06 '19 at 17:30

2 Answers2

0

I just now ran into this same error while trying to run the Getting Started tutorial from OpenJFX.io. The specific place I ran into trouble was in the section on configuring and running a modular MAVEN project, step 5 "Run the project". The instructions there are as follows:

Click Run -> Run As -> Maven Build -> New launch configuration to create a new configuration. Name it hellofx, and add the required goals:

clean javafx:run

I omitted this step, as I could not find the place to enter a goal. Running then generated the identical error.

I had overlooked that the run configuration has a field labeled "Goals". It is located on the "Main" tab, mid-screen. Once I entered the required text in this field, the "hellofx" tutorial ran without error.

If the "Goals" field does not show on your run configuration for the project, I am going to guess that it will appear if you create a new run configuration by selecting the "Maven build" option.

AFAIK, my Spring Tool Suite 4 is based on Eclipse, and the Maven aspects will be similar, allowing for version evolution over time.

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41
-1

Add a configuration similar to the following to your POM:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</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>

Source