Reputation: 373
I have 2 different projects in java and I need to do the following with them: After a certain button from the program A is pressed, the program B is loaded and the program A is closed. Even though both projects have classes and dlls in common, I really do not want to merge everything into one single project.
I have done some searching and I found out that one possible solution would be to load the program B from a .jar using the following example of code:
btnMyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Runtime.getRuntime().exec("java.exe -jar \\url\\ProgramB.jar");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
I tried many variations of this (without the ".exe"
, for instance), and I made sure that the ProgramB.jar
was in the same folder of its dlls, but nothing of this seemed to work.
So, I tried to open the ProgramB.jar
directly (via Windows), and apparently everything was ok.
Later on, I tried to execute the ProgramB.jar
via cmd (because I thought that the command "java.exe -jar \\url\\ProgramB.jar"
could be executed on it).
Even though I have set the library path (java -Djava.library.path=\\url\\ -jar \\url\\ProgramB.jar
), an UnsatisfiedLinkError was thrown every time(X.dll->cannot find dependent libraries).
(Note: I won't be able to provide all the exception messages for a while because by the moment I do not have the program with me...)
Anyway, I am not sure exactly what I am doing wrong, but apparently there aren't any problems with the dlls implementation, since I was able to execute the program at least once. Any ideas are welcome.
Upvotes: 1
Views: 873
Reputation: 593
The problem is java does not recognize the dll if is not in java.path
So first solution:
put your dll in a java.path for example in windows C:\Windows\System32
Second solution
Set a new java variable which indicating the path where exist .dll file.
Also VMoption must be like:
-Djava.library.path="path_to_dll"
This is not correct -Djava.library.path=path_to_dll\\dllname.dll
Upvotes: 1