我想获取项目的maven dependency
,并将其用作classpath
的命令行项目(Windows批处理)。
这是我根据batch
文件中的maven dependency plugin所做的。
call mvn dependency:build-classpath -Dmdep.outputFile=test.txt
java -cp `cat test.txt` com.hqly.main.Hqly
但cat
命令未执行且classpath
未正确设置。它没有看到我的main
课程。
我在尝试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.
答案 0 :(得分:1)
与Linux不同,Windows不使用反向标记作为将命令结果作为程序参数传递的方法。
您可以查看此问题,了解有关如何在Windows中解决此限制的一些想法:Batch equivalent of Bash backticks。这样的事情应该有效:
for /f %%i in (test.txt) do set HSQLY_CLASSPATH=%%i
echo Classpath is "%HSQLY_CLASSPATH%"
java -cp %HSQLY_CLASSPATH% com.hqly.main.Hqly