简体   繁体   English

来自Java命令行的Maven依赖插件的classpath文件

[英]classpath file from maven dependency plugin for java command line

I want to get the maven dependency of a project and use it as a classpath for my command line project (windows batch). 我想获得一个项目的maven dependency ,并将其用作我的命令行项目(Windows批处理)的classpath

This is what I did as per the maven dependency plugin in my batch file. 这是我按照batch文件中的maven依赖插件所做的。

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. 但是cat命令没有得到执行,并且classpath没有得到正确设置。 Its not seeing my main class. 它没有看到我的main班级。 Am getting the below error while trying to execute 尝试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.

Unlike Linux, Windows does not use back-ticks as a way of passing the result of a command as a program argument. 与Linux不同,Windows不使用反引号作为将命令结果作为程序参数传递的方式。

You can check this question for some ideas on how to work around this limitation in Windows: Batch equivalent of Bash backticks . 您可以检查该问题,以获取有关如何在Windows中解决此限制的一些想法: 与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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM