这是我的文件结构。
├── 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日更新
感谢鲍姆加特纳先生的建议 我将数据移动到/ 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$1.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
答案 0 :(得分:2)
使用您的文件结构algs4-data不可见。启动应用程序时,exection的根目录是目标文件夹。通过不将algs4-data放入像/ src / main / resources这样的src文件夹中,它不会被复制到目标/类中。
解决方案应该在不知道您的代码或测试的情况下工作:将algs4-data复制到src / main / resources。