I have a project in eclipse that uses rxtx. I have the same project in netbeans, too. They work perfectly, but neither of them works, when I create runnable jars.
I do not know what I do wrong. I tried to change classpaths, adding external libraries...
I must be doing something wrong, but can not not figure out what.
If there is out there somebody who managed to get rxtx work, can you explain step-by-step what to do?
See my answer here for a fuller explanation, but essentially you must extract the RXTX dll's (or so's, or other native libraries) from the JAR file and place them somewhere on the file system before you attempt to load them (which in this case involves initialising RXTX.) You cannot load the native libraries from inside the JAR file, it won't work.
However, you can have a JAR file that, when it runs, extracts the appropriate native libraries to a temporary location and then loads them from there. The libraries can be set to delete on exit of the VM so they don't end up clogging up the system.
Related
I'm very new to java. I'm developing a tool that checks if your PC meets some set of specifications. This included writing and executing a separate batch file and including an API (SIGAR) for the model of the CPU.
My problem is that when I tried exporting it to Runnable JAR in eclipse, and I ran the resulting JAR from command line, it gave me lots of 'DLL not included in build path' Exceptions. After including the folder that contains the API DLL in the build path, I got similar exceptions. The thing that fixed it was adding the folder containing the DLL to environment variables (PATH) in Advanced System Settings.
Questions:
The JAR now works fine on my computer, but what about the users who download the JAR? Will they also need to add the DLL to environment variables? If so is there a way the JAR can do that for them?
My JAR won't run with a double-click, but will run from command line. Is there any way around this that will carry over to users who download the JAR too?
If the user downloads the tool and can't run it because they don't have the right version of the JRE, will the tool notify them? If not, is there a way around the user having to update JRE or will wrapping as an EXE suffice?
Thanks in advance, much appreciated. Lots of questions.
Q1: The JAR now works fine on my computer, but what about the users
who download the JAR? Will they also need to add the DLL to
environment variables? If so is there a way the JAR can do that for
them?
You can put a DLL inside a JAR file:
How to make a JAR file that includes DLL files? (Hint: read both answers ... completely.)
However, when you distribute a JAR containing a DLL, you then have the problem that different platforms require different DLLs (or whatever). Even with Windows you have the problem of 32 bit versus 64 bit DLLs.
Q2: My JAR won't run with a double-click, but will run from command
line. Is there any way around this that will carry over to users who
download the JAR too?
You cannot address that problem in a JAR file. The "double-click to run" functionality is implemented by the OS. The best way to provide this kind of functionality is using (platform specific) wrapper scripts that are double-clickable.
Q3: If the user downloads the tool and can't run it because they don't
have the right version of the JRE, will the tool notify them? If not,
is there a way around the user having to update JRE or will wrapping
as an EXE suffice?
Unless you have a JRE installed, the JAR file is just a passive blob of data. (A ZIP file, actually).
If the user has a JRE that is too old, then either the JRE will be unable to load any classes in the JAR (because the classfile version number is wrong), or you will get errors because of missing (system) classes.
The only hope would to do something like providing a wrapper script to launch your application that checked the JRE version before attempting to launch the JAR.
As a general rule, if you want to do fancy stuff like this you need to distribute your program in an installer, not as a bare JAR file.
I have a project in eclipse. It does everything I want it to do when I click on the green circle play button in the IDE - opens the window, plays the stuff, everything. But, try as I might, I cannot figure out how to get it to do that outside of eclipse.
My project uses the processing.core library to do some of its stuff, but I am unable to get the project to function in the Processing IDE, because of some stupid stuff about one of my classes not being a valid substitute for the type parameter for Collections.sort(List<T>). If anyone knows how I can get it to export from the Processing IDE, that would be excellent.
I need to be able to email/upload to the internet/otherwise transmit some kind of file/folder/webpage that allows the recipient to, without much technical knowledge or work on their part, view a window or something that allows them to view and interact with the program in the same way I am able to interact with the window that Eclipse launches when I press the play button at the top.
I have tried several different ways of accomplishing this, but none of them have worked. I tried exporting a runnable .jar, but it wouldn't let me include the referenced libraries. I tried a regular .jar, but I don't know how to package that up with whatever is needed to be able to view it. I've even tried using the fat jar eclipse plugin for it, too, but I ran afoul of something about being unable to find the main PApplet class for the project.
If anybody knows how to get what I want to happen, or knows of a good tutorial on how to do what I want, I would greatly appreciate any sort of assistance or guidance or anything.
Google has been unhelpful in turning up solutions to this problem, because most of the results I have found were just other people asking the same or a similar question, and then either no answer, or something I had already tried, with no indication of exactly what sort of options or settings I needed to give it in order to accomplish the task.
I am using the processing.core.jar from version 2.0b7, but I don't think that would make a difference, although I plan to try it with different versions if I can't figure out anything else.
A copy of my project folder can be found at https://www.dropbox.com/sh/1n4curhxbgi8fye/A5F6_l7xQu
All the data I have is stuff I've concatenated together from successive versions of the file at http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt
I've done a quick test on OSX and had to tweak your eclipse project a bit:
You are linking to .jar libraries using absolute path. I recommend using keeping libraries relative to the project
I ran into some memory issues and had to add a couple of compiler flags
Added a main method in Earthquaker.java to initialize as an application.
main looks like this:
public static void main(String[] args) {
PApplet.main(Earthquaker.class.getSimpleName());
}
In eclipse you can export a runnable jar via File > Export > Java > Runnable JAR file. Here are a couple of screenshots:
Personally I prefer using the "Copy required libraries into a sub-folder..." option in case I need to update some dependent .jar independent of the main application .jar.
For reference I've uploaded the modified eclipse project here(Java SDK will need to be changed). The exported runnable jar with a bash script is available here.
And here is the bash script itself which should run on Linux as well:
java -Xms128M -Xmx1024M -jar Processing-DataVisualization.jar
Pretty cool project btw.
Create a simple jar. Create a batch file and specify the class path. Save the batch file. Runnin the batch file will run the app
#ECHO OFF
set CLASSPATH=%CLASSPATH%;myjar1.jar;myjar2.jar;
java mypackage.MyClass
I've looked through a number of posts, and tried what I've found to little success. Here's the setup:
I wrote a program in Java, worked alright, but we needed to switch cameras. This camera is Twain compatible (yuck). I rewrote the program (pretty simple), using JTwain, and it runs just fine in netbeans. I built it, and it runs just fine on my computer. However, when I try and transfer the .jar (and companion library etc.), it runs fine until it needs to take an image, then I get the error:
java.lang.UnsatisfiedLinkError: no aspireJTwain in Java.library.path.
I've tried bringing the base twain package over, adding the system environmental variables, checking the java distribution. I can run the JTwain test file (to make sure you have JTwain and everything is hunky dory).
If someone could please lend a hand, I'd be much obliged.
Can you check to make sure that you have followed the directions from the The Java Developer's Guide to JTwain v9.
6.3 Software Packaging and Distribution
There are two files about JTwain you need to distribute along with
your own binary code. One is JTwain.jar, which is like any other java
library, you can just copy it and put it in the class path. The other
one is AspriseJTwain.dll, the native library. There are many ways to
'install' this dll file, you can: Add the folder containing the
native library to the system path, or Copy the native library to
jre/bin directory – 'install' the library to the JVM, or Copy the
native library to a specific location, e.g. C:\AspriseJTwain.dll,
before calling SourceManage.instance(), call:
SourceManage.setLibraryPath(“ C:\AspriseJTwain.dll ”);
I wrote a simple synth instrument gui that works well on my machine. However, as soon as I put it in a jar file, it no longer plays sounds when executing that jar file. I assume that has to do with the soundbank. Either way, I cannot get it to play a note on my machine when I run the jar file, so I presume it will not work on another person's machine. Any thoughts as to what might be going on? Thanks.
-Matt
did you pack in .jar file even sounds that should play?
How do you run your .jar file?
Something about resources in your .jar file (what could be your case) you can read here.
About running .jar files and troubles with them you can read here and here.
Good luck and let us know if it helps you.
You are probably running your tests in an IDE using the java JDK but testing the app from the jar using the JRE.
See on how to fix it: http://www.jsresources.org/faq_midi.html#jre_soundbank
I am using JNI to wrap a few native functions in a closed-source PDF library. It has an dependent fonts directory which must be in a subfolder of the calling application's directory. In my experience, it is standard to seek based on the current working directory. Thus, the problem.
When loading the JNI code into a Java application, the current working directory is correct. However, the calling application's directory is java.exe's bin directory. I have verified that putting the dependent fonts folder in C:\Program Files (x86)\Java\jre6\bin folder works as expected.
The library seems to be using a C++ GetCommandLine() call, or something similar to determine where the fonts directory should be. Obviously, this is an unacceptable solution.
I'd like to avoid calling an external EXE. But the only workarounds that I've come up with are:
Compile an EXE, place in Java project directory, and use Java's Runtime.exec() to execute. (this does work)
Make JNI code launch a separate process which does the same as above (gains nothing but more complexity)
Any ideas on how I can circumvent this problem? When Java applications are compiled as a runnable JAR, is the resultant command line still the JRE's C:\Program Files\...java.exe?
A Java executable maker can create an executable *.exe from your Java application without any native coding or compiling. You can put that executable, the jar files, the fonts and other application dependencies into a single install directory.
Exe4j is one of the executable makers that will support this, for Windows. It does not require any assumptions about the current working directory. This is important in the frequent case where you have no control over what the working directory is when the application is launched.