would it be possible to bind a Java application to a Cocoa graphical interface?
I'm working in Eclipse right now, on my mac, and am wondering if Interface Builder could be used to construct a new interface so that I don't have to look at Swing all day.
Any ideas/suggestions? Thanks!
Check out Rococoa. It's a great Java-Cocoa compatibility layer that's built on top of JNA.
If you don't find what you are looking for in the documentation, try the mailing list. The Rococoa developers are very helpful.
P.S. I'm not a Cocoa/Objective-C expert, but the section on "NIB loading" might be what you're looking for.
Some good (ANCIENT) historical info here (written 2002):
http://cocoadevcentral.com/articles/000024.php
The original Java/Cocoa bridge (since Mac OS X 10.0) became marked deprecated in 10.4, and is considered unusable. The Rococoa answer above is basically your best bet. Just thought I'd chime in with the historical note.
The Java Objective-C Bridge provides a simpler and lighter-weight mechanism (than Rococoa) for accessing Objective-C APIs. It doesn't require you to generate any stub wrapper classes. It just provides a "Proxy" class for accessing the Objective-C API at runtime.
Some examples:
Loading a NIB file with a WebView
Loading a NIB file
An NSSavePanel wrapper
Accessing NSProcessInfo from Java to solve App Nap problem
Full disclosure: I'm the author of the Java-Objective-C bridge
Related
We want to use existing C# sources within our Java project. So far, this would not be a great problem since using e.g. Java Native Interface (JNI) is quite straight forward.
The problem is that the software shall also run on non-windows OS. So, we can compile the C# sources with Mono in order to make them executable on e.g. Linux. But how about the integration within Java? JNI or any COM-based solutions for C# <-> Java interoperability are OS-dependent and only work e.g. on Windows.
One possible solution would be the implementation of webservices. Has anybody another idea of how to solve this problem? I would be very thankful for alternative suggestions!
Thanks very much!
Regards
This is maybe not an "answer" as such, more a bit of discussion of how I viewed a similar (I think) situation.
I had a major investment in a C#/.Net-based client-server style system. So when I decided that I also wanted to support an Android "client" app I looked into various options. To me the most important factor was to maintain my C# classes as the defining classes for the object interchange between the existing system and the to-be-written Java Android app.
What I eventually settled on, and tweaked to my liking, was a system where Google Protocol Buffers is the interchange media. (If you're not familiar with them they are a sort of JSON-like interchange format.)
https://developers.google.com/protocol-buffers/
At the .Net end I use ProtoBuf-Net, written by Marc Gravell (he works here at SO, I believe). It includes the ability to take .Net objects and generate .proto files, the defining file for Protocol Buffers.
https://code.google.com/p/protobuf-net/
At the Android end I use ProtoStuff, written by David Yu. There is a part of his code that takes a .proto file and generates the corresponding Java classes.
https://code.google.com/p/protostuff/
One problem I encountered was that this didn't work well for my .Net classes that are derived classes, which was most of them. I created a workaround that is described in my comment to the answer here:
How to get protobuf-net to flatten and unflatten inherited classes in .Net?
This is now working to my satisfaction.
Note that I haven't talked at all about how the Android app connects to the Windows-based system and how the communications is performed. That was secondary for me - my primary consideration was making the C# class definitions the definitive definitions and having Java classes created from them automatically, and then the object-to-object interchange. (In the event I'm using a home-made TCP/IP communications link, but the actual communications could be anything, probably also web services.)
Hope this helps.
So I did a lot of research on this topic and want to share my findings with you:
One (from a technical point very attractive) option is to use commercial bridges between Java and .Net. For sure, the most popular products are JNBridge and Javonet. Both products seem to be quite easy-to-use, have good support and seem to be very sophisticated. Especially JNBridge already supports bridging between Java and Mono too, which allows the portation to also non-Windows OS, which is one of our main requirements as stated above. Javonet also wants to integrate Mono and is going to release this feature soon. However, both solutions are commercial and one needs to weigh their features against the respective costs. Nevertheless, from a pure technical point of view, they look great and also state to enable very fast communication between Java and .Net (faster than with web services).
Another option is to connect Java and .NET via COM. Since COM is generelly defined platform-independently, this could work on multiple OS. There are lots of open source projects that could be used for such an implementation, such as EZJCOM, J-Interop, JACOB or JCOM. The main restriction (expecially for our project) is that Mono only supports COM-interoperability under Windows (yet). So, this is not really an option for us. But if you want to create Java-.NET interoperability on Windows only, this is a good way.
The straighforward way of integrating Java and C# is to use Java Native Interface (JNI). You can also find manifold implementations that make JNI more easy to use, the most popular one is probably jni4net which seems to be a very active and frequently used project. But there are also others with specific pros and cons, such as Caffeine, Espresso or csjni. Finally, JNI is not 100% platform independet. It is applicable on different platforms, but you have to generate platform-specific code which makes it clearly less usable for our purposes. If you limit your application to Windows, jni4net seems to be a very good choice.
The third option could be to run both the Java and the .Net part within a Common Language Runtime. Ikvm.net is one possible and very popular solution therefore (as mentioned above by Samuel Audet). The drawback of this option is the loss of features and efficiency of the JDK.
The last and surely most generic alternative is to set up webservices between the Java and the .Net world. For this solution, one needs to find appropriate ways for serializing/deserializing objects from/to Java and .Net. There are manifold possible solutions for that available. RenniePet mentioned a sophisticated solution based on Protocol Buffers. Others exist as well such as http://java-cs-bridge.sourceforge.net/. This option might have a potential drawback when considering communication runtime, but may be the way to go for us.
Hope this may help anyone in the future that is confronted with the same problem.
I know how to create small desktop applications in Java. I want to know, can I make Windows Metro style apps in Java? Because on the web only C++/C/C#/JavaScript etc. are mentioned. If yes can you please give me some reference for a quick start. If not which one will be easiest language to start?
You can only create metro style apps with C#, VB, JavaScript and C++. There is currently no support for authoring metro style applications with Java.
You cannot make metro style apps with Java.
For the other part of your question, regarding starter's guide and which language is easy, MSDN has a starter's guide which helps building new metro style apps, this, this and this should be helpful.
And which language is easiest, well it depends on the developer, someone who has been developing .NET or WPF or Windows Forms applications maybe more comfortable with he familiar environment and may prefer developing using C++ and XAML or VisualBasic, depending on what he has been using before, while someone coming from web development may prefer javascript.
For new developers, i would recommend using C# and XAML, but again it is my choice, and not everyone will agree with it.
Here is another link which points to guides at MSDN, and adds some additional detail.
I believe you will not be able to use Java and WinRT. The best option for you to try is C#, because this is the language that is closest to java, in my opinion.
WinRT is still based on COM, so you should be able to access it from Java using something like the Java-COM bridge. Using that would probably be quite hard (you'd have to use strings for method names etc.).
If you wanted to use WinRT comfortably from Java, that would require modifying the Java runtime and possibly also the compiler to make them aware of WinRT types.
Actually you can quite easily write a metro style web application by using a CSS library like this one: http://metroui.org.ua/
With this CSS, it is possibly to generate plain old HTML with Java on the server side (e.g. via a servlet) and then reverence the CSS classes.
I did this by using the org.apache.ecs library (it's very old but it works pretty good).
C# and Java are similar, but with different Frameworks. Look into developing Metro Style apps in C#. Remember to sign up for a developer's license for Windows Store Apps!
You could write your app in Java and cross compile into JavaScript using GWT. We do this successfully with a couple of Windows (Phone and Desktop) apps. Additionally, the code can be shared with your iOS and Android ports.
here what i found in sourceforge.net
http://sourceforge.net/directory/os:windows/freshness:recently-updated/?q=slibrary
this is the most close ui to metro theme i saw.
I'm looking for Java bindings for XLib.
Specially, I need to be able to reparent an X windows application from within Java.
Ideally I would like to do this by making the X windows calls directly from java.
I don't know anything about XLib... but recently I ran across JNA and it seems that it can talk with system APIs so give it a look if you wish:
http://java-native-access.github.io/jna/4.4.0/javadoc/
Good Luck!
I've created xcb (successor of xlib) bindings for Java through SWiG. You can find the code here:
https://github.com/Zubnix/xcb4j
It's a rather large but straightforward implementation and should work once you have all the required xcb module headers installed.
Are there inexpensive or free gateways from .NET to Java? I'm looking at some data acquisition hardware which has drivers for C/C++ and .NET -- I really don't want to do any programming in .NET.
Update: I haven't done what I originally wanted to do, but I've done something similar, using JNA to encapsulate some functions from a DLL, in order to control a USB hardware device from Java. (the DLL comes from the device manufacturer) It works really nicely. Thanks!
You could also try to use JNA for accessing the native library. JNA provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java codeāno JNI or native code is required. If their API is fairly straight foward, this might be the path of least resistance.
See their getting started guide where they call some native code (printf and GetSystemTime).
Well, there's JNBridge and EZ JCom, just from a Google search.
You could also use IKVM which is a slightly different approach.
(Any reason for not wanting to learn .NET, out of interest? It's a nice platform, and C# is a lovely language...)
If they have C++ versions of the drivers then you could write a wrapper around it using JNI and then load that in Java. JNI can be a bit of a pain, but it would let you use the C++ version of their drivers and not have to deal with .Net at all if you don't want.
I am partial to the recommendation to jump in the deep end with C# since it is so similar to Java. I did this and used IKVM to compile my favorite Java libs. to .NET assemblies and you get [nearly] all the core java runtime classes to boot, so if you tire of trying to find just the right C# collection type, you can always go back to java.util. (No generic collections though. Not sure why.)
Depending on what platform you're on, you have several choices for free IDEs too. For windows you can get Visual Studio Express for free but I also use SharpDevelop. You can also get the Mono IDE on Linux (and a few flavours of Unix, I think ?).
The C# learning curve is shallow if you already know Java. I only blew off 1.5 limbs on landmines that came out of nowhere for reasons I still don't understand, but workarounds were easy to come by. The worst thing about it was the darn developer docs which are AWFUL on account of being so slow. I really miss the snappiness of JavaDoc. Not only are the online docs incredibly slow, the problem is compounded by someones's iffy decision to put class summaries, constructors and methods/properties all on seperate pages so it just takes forever. Someone said to get the docs installer and install docs locally for a slightly improved experience. Not a bad idea I suppose.
I am author of jni4net, open source interprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
If you have a Java application, the JNI mentioned by the others will be the way to go. You write some wrapper classes, and that's it.
If writing the wrappes is a too big task (depending on the number of methods you have to wrap), have a look at SWIG . I think it generates wrappers automatically, but I never actually used it.
If you want to code in the Java language, but you don't care if your program will run on the JRE/JVM, then you might as well use Microsoft J#. Basically, it's writing Java-Code wich is compiled to .NET-Bytecode and can use the .NET classes of the driver as well as your existing Java classes. With J# you will run into problems if your existing Java-code is newer than Java 1.4, look at this question on how to solve them.
From that point on, you could later add code in J#, C# or any other .NET language. However, you won't get back to the JRE/JVM easily.
I'm wondering if a Java library can be called from a VB.net application.
(A Google search turns up lots of shady answers, but nothing definitive)
No, you can't. Unless you are willing to use some "J#" libraries (which is not nearly the same as Java) or IKVM which is a Java implementation that runs on top of .NET, but as their documentation says:
IKVM.OpenJDK.ClassLibrary.dll: compiled version of the Java class libraries derived from the OpenJDK class library with some parts filled in with code from GNU Classpath and IcedTea, plus some additional IKVM.NET specific code.
So it's not the real deal.
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
You can call Java from .NET if you wrap it in some form to make it accessable and the easiest way is typically to use a Runtime bridge like
http://www.jnbridge.com/
Other way is to wrap your API with java webservices.
check this also http://www.devx.com/interop/Article/19945
Nothing out of the box.
Most java/.net interop that I know uses web services.
If you can create COM components with Java, you can use tlbimp to create an interop assembly for using in VB.Net.
If can create standard DLLs that can be used from C++ with Java, you can write P/Invoke declarations and call them from VB.Net.
If you can create a web service with Java, you can generate proxy class from the WSDL and call it from VB.Net.
In any case, chances are the Java component will live in a separate process. I doubt you can load both the Java VM and the CLR in the same process.
If you have the source code and compile it using the J# compiler, then the answer is yes. If you want to call any pre-Java 2 (aka 1.2) libraries, then these are included pretty much verbatim with J#. More recent stuff is going to be tricky though (i.e., it's not there).
An example where this is used commercially are the yFiles graph layout algorithms from yWorks. These were originally just a Java library, but for the past few years they've been offering a .NET version, which is just the Java version compiled with Visual J#.
It's not without problems, and there are some limitations that you can't get around, but it can be done. So... unfortunately this answer looks pretty shady as well.
You could use JNI to instantiate a virtual machine and then use Java Classes. It will be some fun, though, because you would need to use C++ as a bridge between VB.Net and Java.
This article in java world has a quick tutorial on how to use Java from C++ and viceversa.
http://www.javaworld.com/javaworld/javatips/jw-javatip17.html
If you have the source, Visual Studio will let you convert Java code into c#.