使用从 .jar 导入的 MigLayout
我通常在 Eclipse 中工作。在我的程序中,我使用来自以下来源的 miglayout-4.0-swing.jar 文件:链接。
.jar 文件中的某个位置是 MigLayout 的类。
我使用这些导入:
import net.miginfocom.layout.Grid;
import net.miginfocom.swing.MigLayout;
//它来自 jar 文件。
在 Eclipse 中我只需添加库:
Java 构建路径 ->图书馆 ->添加 JAR/添加外部 JAR -> miglayout-4.0-swing.jar 的路径
所以在一切正常的情况下。
但我需要从终端运行它:java(我不使用包,所以我只使用 bin 中的类),但 .jar 文件存在问题,因为 myMain 类可能不知道该类的类在哪里.jar(不适用于导入上部)。 我尝试将 .jar 文件复制到类所在的同一目录中。没有帮助。 我应该怎样做才能正确添加.jar文件?
I'm usually working in Eclipse. In my program, I'm using this miglayout-4.0-swing.jar file from this source: link.
Somehere in the .jar file is class with MigLayout.
I use these imports:
import net.miginfocom.layout.Grid;
import net.miginfocom.swing.MigLayout;
//It's from the jar file.
In Eclipse i just add library:
Java Build Path -> Libraries -> Add JARs/Add external JARs -> path to miglayout-4.0-swing.jar
So in Everything working.
But I need to run it from terminal: java (I don't use packages so i use just classes from bin) but there is the problem with the .jar file, cause myMain class probably don't know where are the classes for that .jar (doesn't work the imports upper).
I tryed copy the .jar file to same directory where are the classes. Doesn't help.
What should I do to add the .jar file correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
命令行
java
命令不知道在哪里寻找 miglayout jar 文件。你应该从命令行运行像Command line
java
command don't know where to look for the miglayout jar file. You should run in from command line like很老的问题,但为了完整起见:
您需要
.
(当前目录)和miglayout-4.0.jar
都位于您的类路径中。您有两种方法可以做到这一点。最简单的是使用 -cp在您的情况下,您需要运行:
或者如果您在 Windows 操作系统上工作:
如果不确定是否需要使用
;
(冒号)或:
(或者操作系统要求的任何内容),您可以查看包含正确分隔符的java.io.File.pathSeparator
。另一种方法是更改 CLASSPATH 变量。
Pretty old question, but for the sake of completeness:
You need both
.
(current directory) andmiglayout-4.0.jar
to be on your classpath. You have two ways to do so. The easiest is to use -cpIn your case, you'll need to run:
or if you work on a Windows OS:
If unsure if you need to use a
;
(colon) or a:
(or whatever the OS is asking for), you can take a look atjava.io.File.pathSeparator
which contains the correct separator.The other way would be to change your CLASSPATH variable.