我有一个简单的java项目,需要外部jar.我用netbeans构建它,在Clean和Build命令之后,我可以在dist目录中找到以下结构:
-myApp.jar
-lib/
library1.jar
library2.jar
Run Code Online (Sandbox Code Playgroud)
典型的,我会说.
现在,我想将依赖库的myApp.jar作为一个exe分发.这可能吗?我正在尝试使用Launch4J.在GUI中我创建配置文件,在cp部分有一些选项
<cp>lib/swing-layout-1.0.4.jar</cp>
Run Code Online (Sandbox Code Playgroud)
但它似乎是classpath,它是我可以参考我的额外罐子的唯一地方.
创建exe文件后,我在exe中找不到dependend libs(exe可以用winrar打开),因此我的应用程序崩溃了.
我怎样才能使exe文件正确?
谢谢你的帮助.
我想在我的 java 类中使用本机 windows api 函数。
我感兴趣的函数是 GetShortPathName。 http://msdn.microsoft.com/en-us/library/aa364989%28VS.85%29.aspx
我尝试使用这个 - http://dolf.trieschnigg.nl/eightpointthird/eightpointthird.html 但在某些情况下,当我使用它时,java会完全崩溃,所以它不是我的选择。
问题是我是否必须用 C 语言编写代码,制作 DLL,然后在 JNI/JNA 中使用该 DLL?或者也许我可以以不同的方式访问系统 API?
我会感谢您的评论。如果您可以发布一些代码作为示例,我将不胜感激。
...
我使用 JNA 找到了答案
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
public class Utils {
public static String GetShortPathName(String path) {
byte[] shortt = new byte[256];
//Call CKernel32 interface to execute GetShortPathNameA method
int a = CKernel32.INSTANCE.GetShortPathNameA(path, shortt, 256);
String shortPath = Native.toString(shortt);
return shortPath;
}
public interface CKernel32 extends Kernel32 {
CKernel32 INSTANCE = (CKernel32) Native.loadLibrary("kernel32", CKernel32.class);
int GetShortPathNameA(String LongName, …Run Code Online (Sandbox Code Playgroud) 我正在尝试用新的修改版本替换集合中的元素。下面是简短的代码,旨在演示我想要实现的目标。
整个想法是我有一个由其他对象的集合组成的对象。在某个时间点,我预计集合中的这个对象(在我的示例手机中)可能需要一些修改,并且我只想修改一个地方的代码。
我知道为了更新对象的属性,我可以在迭代集合时使用 setter,如下所示。但也许有更好、更通用的方法来实现这一目标。
public class Customer {
private int id;
private Collection<Phone> phoneCollection;
public Customer() {
phoneCollection = new ArrayList<>();
}
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
和电话类
public class Phone {
private int id;
private String number;
private String name;
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
和
public static void main(String[] args) {
Customer c = new Customer();
c.addPhone(new Phone(1, "12345", "aaa"));
c.addPhone(new Phone(2, "34567", "bbb"));
System.out.println(c);
Phone p = new Phone(2, "9999999", "new name");
Collection<Phone> col = c.getPhoneCollection();
for (Phone phone …Run Code Online (Sandbox Code Playgroud)