0

I want to get the maven dependency of a project and use it as a classpath for my command line project (windows batch).

This is what I did as per the maven dependency plugin in my batch file.

call mvn dependency:build-classpath -Dmdep.outputFile=test.txt
java -cp `cat test.txt` com.hqly.main.Hqly

But the cat command is not getting executed and the classpath is not getting set correctly. Its not seeing my main class. Am getting the below error while trying to execute

[INFO] --- maven-dependency-plugin:2.1:build-classpath (default-cli) @ hqly ---
[INFO] Skipped writing classpath file 'C:\Users\chandrans1\Desktop\GitHub\hqly\test.txt'.  No changes found.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.926s
[INFO] Finished at: Mon Jun 16 15:44:39 BST 2014
[INFO] Final Memory: 8M/109M
[INFO] ------------------------------------------------------------------------
Exception in thread "main" java.lang.NoClassDefFoundError: test/txt`
Caused by: java.lang.ClassNotFoundException: test.txt`
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: test.txt`.  Program will exit.
Sajan Chandran
  • 11,287
  • 3
  • 29
  • 38

1 Answers1

1

Unlike Linux, Windows does not use back-ticks as a way of passing the result of a command as a program argument.

You can check this question for some ideas on how to work around this limitation in Windows: Batch equivalent of Bash backticks. Something like this following should work:

for /f %%i in (test.txt) do set HSQLY_CLASSPATH=%%i
echo Classpath is "%HSQLY_CLASSPATH%" 
java -cp %HSQLY_CLASSPATH% com.hqly.main.Hqly
Community
  • 1
  • 1
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254