在Windows命令行中将Jar文件添加到Buildpath [英] Add Jar File to Buildpath in Windows Command Line
问题描述
我非常恼火,不得不问这个,但我不能得到它的工作。目前我有一个项目:
5 src /文件夹中的类
2 JARS命名为profiles.jar和
classifier.jar在根文件夹
我想创建一个makefile? 。或批处理文件?以编译和运行这些类 FROM THE WINDOWS COMMAND LINE ,但首先将jars添加到构建路径?我不知道我该怎么走这个
当我尝试这样做,它说,没有找到类,很可能是因为我没有添加jar到buildpath正确。在命令提示符下运行此命令需要使用什么命令?
感谢
Philip
EDIT
感谢您的帮助,我有很多麻烦让它工作tho
目前我有一个项目5 src文件夹中的类和jar文件夹中的2个jars
这里是命令
Im运行:
设置
CLASSPATH = C:\wamp\www\\\
ews\UserProfiling\jars\classifier.jar
; C:\wamp \www\\\
ews\UserProfiling\jars\profiles.jar
然后从根文件夹,运行: / p>
javac src / *。java
然后:
java -cp ./src:./jars/*
src / Interaction
交互是主类,Im得到各种noclassfound错误,我做错了什么?
非常感谢菲利普
错误
java -cp ./src:./jars/* Interaction
线程main中的异常
java.lang.NoClassDefFoundError:
交互原因:
java。 lang.ClassNotFoundException:
交互
在java.net.URLClassLoader $ 1.run(未知
源)
在java.security.AccessController.doPrivileged(本机
方法)
at java.net.URLClassLoader.findClass(未知
源)
at java.lang.ClassLoader.loadClass(未知
源)
at sun.misc.Launcher $ AppClassLoader.loadClass(未知
源)
在java.lang.ClassLoader.loadClass(未知
源)
在java.lang.ClassLoader.loadClassInternal(未知
源)找不到主类:
交互。程序将退出。
在版本早于或等于Java版本5中,每个jar单独,以及您的源代码的根目录,例如
java -cp a.jar:b.jar: c.jar:./ src MainClass
在版本6中,您可以为jar使用通配符, p>
java -cp ./src:* MainClass
但是它可能会更清洁你的jar到一个子目录中
java -cp ./src:./jars/* MainClass
所以基本上你的makefile或start脚本需要构造
更多信息 - Sun docs(v6)/ strong> - 响应你的第二次编辑,你需要指定完整的主类名,所以如果类是在一个名为'com.mypackage.MainClass'的包,那么你需要做:
java -cp ./src:./jars/* com.mypackage.MainClass
我还建议先让命令作为一个独立的命令,然后再让整个脚本运行。通过移除移动部件,可以更快地进行调试,并更容易看到发生了什么。
Im quite annoyed at having to ask this but I cant get it to work. Currently I have a project with:
5 Classes in the src/ folder
2 JARS named profiles.jar and classifier.jar in the root folder
I want to create a "makefile?" or "batch file?" to compile and run these classes FROM THE WINDOWS COMMAND LINE, but first add the jars to the buildpath? Im not sure how I go about this
When I try to do it, it says that the class is not found, most likely due to me not adding the jars to the buildpath correctly. What are the commands I need to use to run this in command prompt?
Thanks Philip
EDIT
Thanks for the help, Im having alot of trouble getting it to work tho Currently I have a project with 5 classes in the src folder, and 2 jars in the jar folder
Here are the commands Im running:
set CLASSPATH=C:\wamp\www\news\UserProfiling\jars\classifier.jar ;C:\wamp\www\news\UserProfiling\jars\profiles.jar
Then from the root folder, Im running:
javac src/*.java
Then:
java -cp ./src:./jars/* src/Interaction
Interaction is the main class, Im getting all sorts of noclassfound errors, am I doing something wrong? Many thanks Philip
THE ERROR
java -cp ./src:./jars/* Interaction Exception in thread "main" java.lang.NoClassDefFoundError: Interaction Caused by: java.lang.ClassNotFoundException: Interaction 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) at java.lang.ClassLoader.loadClassInternal(Unknown Source) Could not find the main class: Interaction. Program will exit.
In version older than or equal to Java version 5 you must specify each jar individually, and the root of your source, on your classpath e.g.
java -cp a.jar:b.jar:c.jar:./src MainClass
In version 6 you can use wildcards for the jars e.g.
java -cp ./src:* MainClass
but it might be cleaner putting your jars into a sub directory e.g.
java -cp ./src:./jars/* MainClass
So basically, your makefile or start script needs to construct a command like one of the above.
More info - Sun docs (v6)
Update - in response to your second edit, you need to specify the full main class name, so if the class is in a package called 'com.mypackage.MainClass' then you need to do:
java -cp ./src:./jars/* com.mypackage.MainClass
I'd also suggest getting the command working as a standalone command first, before getting the whole script running. By removing moving parts it will be faster to debug and easier to see what's going on.
这篇关于在Windows命令行中将Jar文件添加到Buildpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!