I am new to java and want to develop a java application which will run continuously like a server.
Is it possible in Java to develop a UI less application which will work continuously? This application should also have JNI support, so functions exported using JNI should get called from a C++ application.
Can anybody tell me the pointers to start?
Help is appreciated, thanks.
Vishal N
It is certainly possible to run without a UI. By the sounds of it you would like to create your Java APP as a console app and then run it as a Windows Service/Linux Daemon (You did not mention the OS). There are java service wrappers out there that lets you run your java code as a service (e.g. this one) or you could write your own.
I recommend this book to learn the JNI. Although it sounds like what you need it not really JNI but rather an interface exposed over TCP or something similar that another C++ app can use to talk to your app. JNI won't allow another process to talk to your app, it is there to extend your Java code with functionality that cannot be implemented in Java itself e.g. calling some Windows API function.
Edit:
By the way, a plain Java Hello World App like this one IS a console app:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
Yes you can develop UI less applications in Java.
I'll expect an application server to handle multiple requests, transactions, security, life-cycle, persistence, etc.
If answer is Yes then I will choose the Java EE route to implement your requirements. I'll implement my business model using EJB3.0 and deploy in one of the application servers i.e. Glassfish, JBoss etc. which will support all features described above without reinventing the wheel.
Note: The solution will also give flexibility to expose your remote methods using WebService, CORBA or JMS.
If answer is No then I might create my own standalone server type application which will listen on some port and communicate through some bespoke protocol.
In order to support JNI -I would expect that you'd have to write a plain JavaBean wrapper or proxy. This proxy would then be used by the JNI.
Yes.
Is it possible in Java to develop a UI less application which will work continuously?
Create a thread or code main thread that will run foreever.
This application should also have JNI support, so functions exported using JNI should get called from a C++ application.
yes , have a look at here
You can certainly develop a Java application without a user interface; I think most folks would agree that it's easier than developing one with a user interface.
Regarding JNI, if I understand the question, you've got it backwards; using C++ as an example, JNI lets you call C++ code from Java, not Java code from C++.
Yes, you can run Java as service (daemon). You can simply run your code a "daemonize" it. This way, it will be detached from terminal sessions and will run in background.
Take a look here:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo022
to see how you can run service inside C.
And here, to check out how to run service part in Java:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo029
Have fun with JNI!
Related
ok, So i searched net for the possible implementation but all that I managed to find is Django projects implementation on Java platform through Jython. But I want to do the reverse, i.e. implement/integrate java project ( which in my case is SAIKU server ) on Django platform.
The question being, is it possible, and if yes, then kindly point me to the solution.
Thanking in advance =)
For your specific requirement, I would suggest using RESTFul API to access the Saiku Server.
However if you need to run Java Classes from Python.
Here are the options available for you:
JCC -- a C++ code generator for calling Java from C++/Python. It produces producing Python extensions which communicate via JNI with a Java virtual machine. As it implies, this would require compilations of every possible call. However this project is backbone of PyLucene project.
CodeMesh. C++ code generator for Java.
Py4J Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine.
JPype allow python programs full access to java class libraries. It is done through interfacing at the native level in both Virtual Machines. However there are no recent development in this front.
In general, having an loosly coupled integration through REST or RCP would be easy to maintain than tightly coupled JNI based implementation.
There's no way to run Java within the Python runtime (which is what it sounds like you want). There are Java to Python "translators" available, but they're terrible. Honestly, if you need a Java server and Django to sit inside the same process for some reason, Jython is the way to go.
There are lots of options outside of that though, off the top of my head:
Implement Python bindings for your server (See PyLucene for an example)
Implement a socket server within your Java server that Python can talk to directly
I want to Use Some Java Code From the WCF Service. Basically I need to intreact with the java application from the .net so how can I make it out for that? Any guidance for that?
I was just wondering that how can i call java code from my .net desktop application? Do I need to create .exe file of my java poject or jar? How would I invoke that java project from my .net desktop application?
Like some code in .net desktopp application will call
void startprocessing ();
code written in java application
Let me Clear the Things What i want to implement..
I have one desktop appplication of windows and I want to integrate my speech recgnition facility in that application which is in java. What I want is to exchange the audio data as binary and some strings from .net application to my java application so I can process on that binary data to convert wav file and etc and recginze it..that is just completed ..but what I need to know is how to send those strings and some binary data to java application and just invoke that java application ?? Do I need to 'use'(?) wcf or other service ?
Going out on a limb here, sounds like you java app needs to expose the method you want to call via a web-service. That's of course assuming you have control over that in terms of the java app you're interacting with. Not sure though you can access that method simply by compiling your java app to native.
You can take a look at JNBridge, which provides interop possibilities between Java and .NET. However, as another poster has suggested, exposing the functionality through a web service is probably a better solution.
A quick Google search will give you plenty of information on how to create web services in Java, but for starters you can take a look at: http://docs.oracle.com/javaee/6/tutorial/doc/bnayl.html
I have Successfully done that with the axis 2 webservice with tomcat apache server with the following link..its too easy .i really got succeeded
http://blog.sencide.com/2011/06/create-web-service-using-apache-axis2.html
I am starting out to build a remote collaboration application.
What I want is for all the actions made in one application to be exactly replicated in an application running in a remote computer.
Kind of like remote desktop/teamviewer - but I need to call the same function in the remote computer rather than transmit image difference information.
I need to modify an existing application and add in the collaboration part.
I have looked into XML-RPC and RMI as ways to execute the commands remotely.
What I want is a method to capture all function calls made in the application.
Can you give me some pointers?
You could use an Aspect Oriented Programming Framework (AOP) like JBoss AOP, AspectJ etc.
http://www.jboss.org/jbossaop
http://www.eclipse.org/aspectj
So you do not have to modify anything of the existing sourcecode.
I have an RMI application that has service implementation and it has a lot of code in it and I do not want to redo the business logic just to support an iPhone app.
Could someone assist me on a best way to access these RMI services using Objective C? Or is there any other way for making this possible, please let me know if this is a terrible question, being a software programmer, I would expect that there would be a way for heterogeneous programs to communicate with each other, so this question comes to me with that assumption.
There's no Java runtime in iOS, nor any support for Java in the SDK, and an Objective-C app can't start up another process on the device (unless it's jailbroken), so there'd be no way for your app to run a JVM. So the only other option I know of (short of rewriting the Java code) would be to make your Java functionality available via web services.
Also, there's no direct way for applications to communicate with each other (or for that matter to even be running in the foreground simultaneously) in iOS.
I have a google app engine application with a GWT client. Most server functionality is accessible through normal GWT RPC calls as usual. I am writing a data mining application in C++ which needs to communicate with the appengine application. Problem is, there are just too many gwt servlets implemented so a rewrite of server code is out of the question.
Any ideas?
If you were using java on the client you could use GWT SyncProxy. Although main usecase of this library was to test remote gwt rpc service, but it can be effectively used for any purpose. As you are developing your client in C++ this might not be an option for you.
If you control the GWT application (that is you can recompile it), you can probably do something like this:
Export RPC related functions into javascript. That is make specific functions of your GWT code made available to be called as normal Javascript functions from within the host page. See this article for a tutorial
Use a embedded browser engine like webkit and load your GWT module script in it.
Call the exported GWT functions as normal java functions.
But it will probably prove to be too much work, so you might be better off refactoring the servlets to expose another JSON/XML based interface in addition to RPC.
Solved, the best way to go is as Tahir suggested. Trying to connect to GWT rpcs directly from C++ is just too much work. The easiest way was to write thin wrappers on the server side as normal servlets and use http and curl from C++. One issue remains about object serialization to JSON or XML. I elected to write a custom annotation on the object fields which I wanted to serialize and then read these annotations at runtime in order to serialize them.