gpt4 book ai didi

java - Maven 文件路径参数 exec

转载 作者:行者123 更新时间:2023-12-02 03:32:59 25 4
gpt4 key购买 nike

这是我的文件结构。

├── 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com