0

This is my file structure.

├── algs4-data
├── src
│   ├── main
│   └── test
└── target
    ├── classes
    ├── maven-archiver
    ├── surefire
    ├── surefire-reports
    └── test-classes

I want to pass the filename with path argument and pipe. But I failed, how can I do that?

mvn exec:java -Dexec.mainClass="edu.princeton.cs.algs4.BinarySearch" \
   -Dexec.args="algs4-data/tinyW.txt < algs4-data/tinyT.txt"

Update: Log information

And it only show this and I have to press 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 ---

Update 06/15/2016

Thanks Mr.Baumgartner suggestion I moved data to /src/main/resources

But when I run the code, it gives warning and build failure.

[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

The update file structure.

.
├── 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
1
  • What was the error message? Can you post your Maven logs? Commented Jun 14, 2016 at 21:49

1 Answer 1

2

Using your file-structure algs4-data is not visible. When you launch your application, the root of the exection is the target folder. By not putting algs4-data into a src folder like /src/main/resources it wont be copied into the target/classes.

Solution which should work imo without knowing your code nor testing: Copy algs4-data to src/main/resources.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks, I do your suggestion, but my build fail and I update my question.
Is algs4-data/tinyW.txt in target/classes?
Yes (I update the file structure), may be it is because I use pipe in the argument?
Can you put your project on github that i can try to run it?
Thanks, I put it on [email protected]:yu-yuxuan/algs4_exercise.git github.com/yu-yuxuan/algs4_exercise
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.