java - Maven 文件路径参数 exec

标签 java maven exec-maven-plugin

这是我的文件结构。

├── 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 文件夹(如/src/main/resources),则它不会被复制到目标/类中。

在我看来,在不知道您的代码也不进行测试的情况下应该可以工作的解决方案:将 algs4-data 复制到 src/main/resources。

关于java - Maven 文件路径参数 exec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37821693/

相关文章:

Java 日志记录说明

java - Mapstruct:尝试映射嵌入对象内的字段时返回 null

java - 在 android 中创建反馈表

java - 自动按字母顺序对成员变量进行排序

java - Spring session jdbc

jakarta-ee - 使用 exec-maven-plugin 运行守护进程避免 `IllegalThreadStateException`

java - 如何配置 exec-maven-plugin 类路径

javaw.exe 占用了我的内存?

java - 运行 npm build 时无法访问 vue.js 前端(frontend-maven-plugin 和 spring-boot 后端)

java - 在 Windows 上使用 exec-maven-plugin 执行 shell 脚本