简体   繁体   English

使用从 .jar 导入的 MigLayout

[英]Using MigLayout imported from .jar

I'm usually working in Eclipse.我通常在 Eclipse 中工作。 In my program, I'm using this miglayout-4.0-swing.jar file from this source: link .在我的程序中,我使用来自以下来源的 miglayout-4.0-swing.jar 文件: link
Somehere in the .jar file is class with MigLayout . .jar 文件中的某处是带有MigLayout 的类。
I use these imports:我使用这些进口:

import net.miginfocom.layout.Grid; 
import net.miginfocom.swing.MigLayout;

//It's from the jar file. //它来自jar文件。

In Eclipse i just add library:在 Eclipse 中,我只添加库:
Java Build Path -> Libraries -> Add JARs/Add external JARs -> path to miglayout-4.0-swing.jar Java 构建路径 -> 库 -> 添加 JAR/添加外部 JAR -> 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).但是我需要从终端运行它:java(我不使用包,所以我只使用 bin 中的类)但是 .jar 文件存在问题,因为 myMain 类可能不知道它的类在哪里.jar(不适用于上层的进口)。 I tryed copy the .jar file to same directory where are the classes.我尝试将 .jar 文件复制到类所在的同一目录。 Doesn't help.没有帮助。 What should I do to add the .jar file correctly?我应该怎么做才能正确添加 .jar 文件?

Command line java command don't know where to look for the miglayout jar file.命令行java命令不知道在哪里查找 miglayout jar 文件。 You should run in from command line like你应该从命令行运行

java -cp path_to_miglayout_jar myMain java -cp path_to_miglayout_jar myMain

Pretty old question, but for the sake of completeness:很老的问题,但为了完整起见:

You need both .你需要两者. (current directory) and miglayout-4.0.jar to be on your classpath. (当前目录)和miglayout-4.0.jar位于您的类路径上。 You have two ways to do so.您有两种方法可以这样做。 The easiest is to use -cp最简单的是使用 -cp

In your case, you'll need to run:在您的情况下,您需要运行:

java -cp "path_to_miglayout_jar/miglayout-4.0-swing.jar:." myMain

or if you work on a Windows OS:或者如果您在 Windows 操作系统上工作:

java -cp "path_to_miglayout_jar/miglayout-4.0-swing.jar;." myMain

If unsure if you need to use a ;如果不确定是否需要使用; (colon) or a : (or whatever the OS is asking for), you can take a look at java.io.File.pathSeparator which contains the correct separator. (冒号)或: (或操作系统要求的任何内容),您可以查看包含正确分隔符的java.io.File.pathSeparator

The other way would be to change your CLASSPATH variable.另一种方法是更改​​您的 CLASSPATH 变量。

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

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