Maven 文件路径参数 exec
Maven file path arguments exec
这是我的文件结构。
├── algs4-data
├── src
│ ├── main
│ └── test
└── target
├── classes
├── maven-archiver
├── surefire
├── surefire-reports
└── test-classes
我想用路径参数和管道传递文件名。但是我失败了,我该怎么办?
mvn exec:java -Dexec.mainClass="edu.princeton.cs.algs4.BinarySearch" \
-Dexec.args="algs4-data/tinyW.txt < algs4-data/tinyT.txt"
更新:日志信息
它只显示这个,我必须按 Ctrl-C
➜ java_algs4 git:(master) ✗ mvn exec:java -Dexec.mainClass="edu.princeton.cs.algs4.BinarySearch" \
> -Dexec.args="algs4-data/tinyW.txt < algs4-data/tinyT.txt"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building algs4 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ algs4 ---
2016 年 6 月 15 日更新
感谢Mr.Baumgartner建议
我将数据移动到 /src/main/resources
但是当我 运行 代码时,它给出了警告和构建失败。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building algs4 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ algs4 ---
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Could not open algs4-data/tinyW.txt
at edu.princeton.cs.algs4.In.<init>(In.java:194)
at edu.princeton.cs.algs4.BinarySearch.main(BinarySearch.java:91)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.821s
[INFO] Finished at: Wed Jun 15 09:29:50 CDT 2016
[INFO] Final Memory: 12M/94M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project algs4: An exception occured while executing the Java class. null: InvocationTargetException: Could not open algs4-data/tinyW.txt -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
更新文件结构。
.
├── src
│ ├── main
│ │ ├── java
│ │ │ └── edu
│ │ └── resources
│ │ └── algs4-data
│ └── test
│ └── java
│ └── edu
└── target
├── classes
│ ├── algs4-data
│ └── edu
│ └── princeton
├── maven-archiver
├── site
│ ├── css
│ └── images
│ └── logos
├── surefire
├── surefire-reports
└── test-classes
└── edu
└── princeton
使用您的文件结构 algs4-data 不可见。当您启动您的应用程序时,执行的根是目标文件夹。通过不将 algs4-data 放入 /src/main/resources 之类的 src 文件夹中,它不会被复制到 target/classes 中。
在不知道您的代码或测试的情况下应该可以工作的解决方案:将 algs4-data 复制到 src/main/resources。
这是我的文件结构。
├── algs4-data
├── src
│ ├── main
│ └── test
└── target
├── classes
├── maven-archiver
├── surefire
├── surefire-reports
└── test-classes
我想用路径参数和管道传递文件名。但是我失败了,我该怎么办?
mvn exec:java -Dexec.mainClass="edu.princeton.cs.algs4.BinarySearch" \
-Dexec.args="algs4-data/tinyW.txt < algs4-data/tinyT.txt"
更新:日志信息
它只显示这个,我必须按 Ctrl-C
➜ java_algs4 git:(master) ✗ mvn exec:java -Dexec.mainClass="edu.princeton.cs.algs4.BinarySearch" \
> -Dexec.args="algs4-data/tinyW.txt < algs4-data/tinyT.txt"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building algs4 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ algs4 ---
2016 年 6 月 15 日更新
感谢Mr.Baumgartner建议 我将数据移动到 /src/main/resources
但是当我 运行 代码时,它给出了警告和构建失败。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building algs4 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ algs4 ---
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Could not open algs4-data/tinyW.txt
at edu.princeton.cs.algs4.In.<init>(In.java:194)
at edu.princeton.cs.algs4.BinarySearch.main(BinarySearch.java:91)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.821s
[INFO] Finished at: Wed Jun 15 09:29:50 CDT 2016
[INFO] Final Memory: 12M/94M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project algs4: An exception occured while executing the Java class. null: InvocationTargetException: Could not open algs4-data/tinyW.txt -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
更新文件结构。
.
├── src
│ ├── main
│ │ ├── java
│ │ │ └── edu
│ │ └── resources
│ │ └── algs4-data
│ └── test
│ └── java
│ └── edu
└── target
├── classes
│ ├── algs4-data
│ └── edu
│ └── princeton
├── maven-archiver
├── site
│ ├── css
│ └── images
│ └── logos
├── surefire
├── surefire-reports
└── test-classes
└── edu
└── princeton
使用您的文件结构 algs4-data 不可见。当您启动您的应用程序时,执行的根是目标文件夹。通过不将 algs4-data 放入 /src/main/resources 之类的 src 文件夹中,它不会被复制到 target/classes 中。
在不知道您的代码或测试的情况下应该可以工作的解决方案:将 algs4-data 复制到 src/main/resources。