Maven 文件路径参数 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 ---

更新 06/15/2016

感谢鲍姆加特纳先生的建议我将数据移动到/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

使用文件结构 algs4-data 是不可见的。启动应用程序时,执行的根目录是目标文件夹。通过不将 algs4-data 放入像/src/main/resources 这样的 src 文件夹中,它不会被复制到目标/类中。

应该在不知道您的代码或测试的情况下工作的解决方案:将 algs4 数据复制到 src/main/resources。

最新更新