Dynamically loading a native library inside Java applet - java

I am trying to write a Java applet that will read from a user's serial port. For this I am using the Java Comm API in conjuction with the RXTX library. I've successfully managed to read data through a local Java application but I can't seem to do the same from within an applet. The problem is that the RXTX library is a native library and I haven't found a way to load this library inside the Java applet. I've found two interesting articles (Using JNI in Applets which references to this article), but both are over 10 years old and I am wondering if there is a newer solution. Or if you can suggest an alternative, I would love to hear it!

Use Java Web Start. You can include the native library as a signed jar and everything should work.
1) put the native librarys in a jar in the ROOT directory
2) sign ALL the jars
3) write a JNLP referencing all the jars (go do a search on how to write jnlp's)
after that it should work

Firstly I'd suggest doing that in an Applet is probably a bad idea.
If you do go ahead anyway, JNLPAppletLauncher may help.

I don't know about applets, other than they're locked down heavily wrt. security/accessing the machine's resources etc.
If you need a web-deployable solution, have you looked at Java Web Start ? See in particular this FAQ entry

Frankly, trying to access devices from a Java applet is a bad idea even if you could make it work, and loading a dynamic library into the conventional applet is an even worse idea; in fact, I'd be astounded if you could find a way to trick a modern browser into doing it. (Consider the possible security implications.)
You're better off, as suggested on other questions, building an app that can be launched with Web Start.

I'd be real interested in the answer here also. My suggestion would be to install the .jar and .dll for RXTX into the \program files\java\ tree. You could install them on the target system before trying to use the applet. I like the idea of using Java Web Start. If you sign the applet, can't you read/write any file on the machine? So you could install the .jar and .dll and then use them afterward?
For windows, I suggest using "Windows Java Serial Com Port Driver" rather than rxtx.
You can download it from http://www.engidea.com/blog/informatica/winjcom/winjcom.html
I've found it much easier to install and use and much more bug-free.
I was unable to use RXTX with USB serial devices because RXTX would crash when the USB port was unplugged. winjcom solved these problems for me, and more.
I'm still trying to decide how to deploy the DLL, but I'm not sweating it because I don't expect the DLL for "Windows Java Serial Com Port Driver" to change.
-Stosh

Related

Applet - Serialport communication

I'm trying to create a simple Java applet that reads data coming in through a serial port.
Is it possible?
By default, Java has no support for communicating with serial ports. There are libraries like RXTX that allow you to do that, but unfortunately RXTX requires a platform-specific native library in order to use the serial ports.
Further complication is that Java applets run in a very restricted sandbox by default, which means you need to a) sign the applet and b) manually install the necessary RXTX libraries on the host computer, which is not that user-friendly.
An alternative solution is discussed in this SO question (in short: use Java Web Start, not an applet, and everything gets a lot easier).
Yes, it is possible. Having said that, I think #andri pointed out the best path to a solution.
For that you can use jSSC lib (Java Simple Serial Connector). Page on google code: http://code.google.com/p/java-simple-serial-connector/
Also see this page: http://code.google.com/p/java-simple-serial-connector/wiki/jSSC_Terminal
This is jSSC based serial port terminal applet. Source code of jSSC-Terminal you can download on "Downloads" page.
Best regards, Sokolov Alexey.

Need Help in Running My Java App

I had created a Java Swing Application, I want to run my applications, in all System, Suppose if a System, does not have JRE, then i have to install JRE using Installer in program without aware of the user knowledgeable that the JRE is installed.
There were a few projects for doing this, but from what I can see they all fizzled out - bottom line seems to be that you need a JRE - especially for swing
The best solution is not to try and install anything silently, but instead to assist the user to install Java. Oracle's deployJava.js was designed to do just that, before embedding applets or launching Java Web Start applications.
While on the subject of JWS, it is also a good choice for installing/running & updating Java rich client (e.g. Swing) apps. on platforms that support Java.
You can generate an EXE out of your Java source but you will still need the JVM to run it on the destination System. So its not real native.
There is no workaround for running non native class files reliably or really at all without the JRE.

How to distribute Java-based software?

Now, don't get me wrong, I am a very competent programmer, but when I program, I typically develop things for the web using scripting languages like JavaScript, PHP, Python, SQL, etc. If I want to develop Java software (I am relatively experienced in Java), how do I distribute it?
Is there any good way to package up Java software in a nice little executable, send it out, and have it run? Alternatively, is there any good way to package up Java in some sort of installer, and send it out to be installed and run?
I'm using Launch4J http://launch4j.sourceforge.net/ it will generate an .exe executable for Windows, if the targeted system don't have JVM, it will tell user to download and get JVM.
You can package Java applications in so called jar-files using the jar tool or any competent Java IDE. These jar-files are self-contained and seldom need any installer.
These .jar files can easily be distributed and executed.
If you're used to web-development, you may also be interested in the Java Webstart technology.
Some links to get you started.
Export to a .jar-file in Eclipse
Lesson: Java Webstart
I have found two approaches to work well, depending on the needs of the end user.
1) Java WebStart - allows for central distribution and easy maintenance, but works best for online users. Require you to have a web site to locate the files - these days this is easy to do on the Google Application Engine.
2) Wrapping up the Java program in a single jar using one-jar, and then using jsmooth to generate an .EXE file which ensures Java is available, extracts the jar-file and invokes Java on it. This works well for users not always on the net, where you want the launch process to be transparent, but is less easy to upgrade than the webstart approach.
I use Maven to handle all the dependencies of my projects and that way when you utilise Maven to build your projects they will compile into one nice executable jar that contains everything so you dont need to worry about getting all your third-party jars in the right place etc.
There are a couple of ways: one is to create an installer that allows your user to install and run it. For this you can take a look at NSIS.... or you can just use Java Web Start where your user can just click the link and launch your application.
Here you will find a large set of options: Open Source Installers Generators in JavaIt is very useful for the "naive" customer or user of your application, to make the installation process as painless as possible. Let them install whatever is needed, DBMS, JVM, JMF and additional options via one installer.
You can also consider use one of the rich client platforms available for Java. The learning curve is probably a lot higher than just creating a jar file and ship it, but you will get a lot for free when it comes to distribution. (Think Eclipse with auto update through an update site).
Do a search for "Eclipse RCP" and "Netbeans RCP" and you'll find the two biggest contenders here. I also performed a serach for "eclipse RCP installer" and one of the hits seems interesting:
http://download.instantiations.com/RCPPackagerDoc/integration/latest/docs/html/gettingstarted/GenInstaller.html
I personally like izpack. It generates a jar file installer that you could wrap up in launch4j, supports things like windows specific shortcuts, is highly customisable through XML and hooks directly into ant.
OneJar is great for smaller stuff, but for larger programs or applications it's nowhere near as flexible and in my experience is rather slow.
Hello you can make an installer for your application.
In the link below you will find a nice help about izpack installer.
http://www.imrantariq.com/blog/?p=89
Link below contains a detailed pdf to make installer with izpack.
http://www.imrantariq.com/blog/?attachment_id=112
cheers

How to run Java USB API for Windows using Eclipse

I understand that there is no complete support for USB for Java in Windows. But jUSB provides a Java USB API for windows which does not provide support for the complete functionality though.
I am trying to install the Java USB API and try it, and the steps provided say he following,
jUSB DLL
Copy the jusb.dll from the folder \InstallationFiles\JusbDll to the \system32 folder
of your Windows directory.
Compile the usb.windows package in Netbeans. Attach a USB device to the
USB and run RunUSBControllerTest.
I am a novice java user, and I currently work with Eclipse. I do not understand what to compile and how to run RunUSBControllerTest alone. Could someone please tell me how to run the application using Eclipse.
http://www.steelbrothers.ch/jusb/
There are other question in stackoverflow like this.
I recommended you:
Learn java before fight with this more complex and undocumented topic.
Use standards APIs like JSR-80. This standard could be a good search start point.
See this thread in forum.java.net
I hope this helps and good luck.

Java Media Framework on client side?

If I’m writing an applet that shows a video sequence (eg. streaming from a camera, or the applet itself is running the on the camera), do my clients need to download the Java Media Framework libraries inorder to see the sequence?
They need to install Java Media Framework on their computers, or you'll need to bundle the JMF together with your applet somehow.
If the applet makes use of the JMF libraries they need to be downloaded to the client machine (where the applet executes). However, JMF gets very little development from Sun (read none) and is pretty much legacy now (subjective).
Depending on how modern the camera is and what codecs it can output it may also be worth considering the video support in either javafx of flash.
Distributing the JMF.jar with your applet is sufficient.
Create a JAR ( Java DLL ) and put all the jar files from the install directory, JMF is 32-bit only, so the x86\java\JMF2.1.1e\lib is where it's usually located.
If you customized the customizer.jar you want that one too.
You can download it from a server like an applet and embed the applet inside and then run it. It's worked for me for 14+ years in Adult Pay sites.
Did you consider to use Java FX? This technology is dealing with this problem of downloading media libraries and so no. Of course. It is still in development. If to be first-adopter is option, it will be worth of considering this.

Categories