How to create large deployable programs with multiple languages? - java

Hi all this is my post on stackoverflow.
I am normally a lurker and find everything I need without posting but was drawing some blanks when trying to picture how this works. Maybe if someone can provide some insight I would greatly appreciate it.
So I understand the software development cycle and know a decent amount about code
(c++ and Java, and visual basic, I am a CIS major with a CS minor in my last year). I can write some programs in elipse using Java and I can even make some basic GUI components in eclipse using Java.
Now onto my 3 part question: I understand one could make a .jar from several .java files and distribute it, but while thinking about a common program like say yahoo messenger (just as an example) I came to the following three part question:
First, being could you write a program like yahoo messenger in just eclipse using Java or would you need other tools like other languages and other development environments, how does the project go from start to finish? (I think I am kind of lost here because I have only wrote command line and simple GUI applications).
Second, Say it was easier to create a feature in yahoo messenger using a different language, how can one write one program in more than one language? Say for example you wanted to write some code in python or c++ and your the majority of your code was in Java, ie your main method is java and you are compiling using JVM. (assuming you cant just stick python or c++ code in a java program) I did some Googling around and saw some things about linking the compiler and including native code to include other language code in a Java project. Links to other reading material is acceptable too if the explanation is too long.
Third- How does deployment work? Say I am done writing the code for my program and want to turn it into an .exe (for windows users) and stick it on my site for people to download. I know windows comes built in with an iexpress utility to create .exe's. Besides distributing a .jar how would one go about turning source into an exe? Thanks again for all your input and time. I am a beginner and trying to wrap my head around these concepts. The answers can be provided in a technical realm or just conceptual either is greatly appreciated.
-Mark

1) I most cases you can write your program in java without needing any other programming language. There are rather rare cases where you need to call a dll from java to interface with some proprietary program, for this you would need to use JNI and C or C++. A perhaps more common case for using multiple languages is for adding scriptability to your application. For example, my company offers a server/client application that is scriptable by users using Groovy, but the server and the rich client itself are written in Java only.
2) The integration of java and another programming language depends on the other language. Integrating Groovy is easy, and I think integrating Python (using JPython) or Ruby (using JRuby) is fairly easy. But it is an effort (not to mention the mental stress of programming in different languages) and I would not recommend doing that unless there's a specific requirement for this.
3) As always, there are several options. See how-can-i-convert-my-java-program-to-an-exe-file for creating a windows executable. Or you can create windows installer using e.g. NSIS. Or use Java Web Start.
If the intent behind this question is getting an idea how some big java rich-client (desktop) applications are written and deployed, I recommend the Eclipse RCP book. This book will walk you through the development and deployment of an XMPP/Jabber messenger client using the Eclipse RCP framework. Be aware though that there is no one true way of creating a big application and other java application frameworks do things differently.

Several IM clients are written in Java, though I would hazard a guess that the mainstream ones would be mostly written in C, C++ or (on the Mac) Objective-C.
Writing the one program in multiple languages has numerous challenges, and the nature of the challenges varies depending on the combination of languages you want to use. In many cases, you will probably not have much luck combining more than two languages. One set of impedance problems is bad enough, three is an almost guaranteed disaster.
You can avoid these problems by splitting a single application across multiple programs, each of which is written in a single language and communicates with the other programs via some kind of IPC mechanism.
Creating an "exe" is also a very language-specific concern. For instance, Java, C#, C/C++, and Python all have radically different deployment stories.

Say I am done writing the code for my program and want to turn it into an .exe (for windows users) and stick it on my site for people to download.
In that case, I'd say you were foolish. ;)
Java Web Start is a better option for deploying a Java based rich client app. from a web site. JWS works for any platform with Java.

Related

How can I protect Java/Javafx code from being seen by final user?

I have been working on a project alone for more than two years for a company. The project is a really big one using rxtx to communicate with a hardware device. I used Java 8 and JAVAFX for the UI. Now it is almost finished and I am starting to search how to deliver the end user application that the company will distribute over its clients.
The problem is that the company I am working with wants the code to be non reachable when the software is between final clients hands because the Java code contains some extremely sensitive information that could have very bad consequences for the company if final clients happened to know them. The clients can literally perform actions they don’t have the right to perform.
So after searching (a lot) and thinking relatively to my case, I understood that giving a JAR obfuscated isn’t the solution. I then tried to generate a JAR and then transform it to an EXE but all I succeeded on was wrapping the JAR into EXE which does not prevent extracting the JAR and then seeing all the code easily. Finally, I found that I should use AoT compilation like GCJ compiler to produce native binary exe from my Java code but here I am stuck because after watching videos and reading articles etc I didn’t manage to find a clear way to produce the native binary exe.
I am now confused since I don’t know if I am on the right path and good direction or if I am totally wrong and there is another way of protecting the code (at least from non professional hackers, I understand that it is not possible to make it 100% safe but I am just searching for a reasonable and good way). How should I manage this final step of my work?
I currently work for a company that has code that we don't want anyone to have access to for the security of our clients and-- less important-- for legal reasons. ;-)
One possible solution you could look into would be to rewrite the code you deem most sensitive into a C/C++ library. It would be possible to compile this into a .so/.dll/.dylib file for the respective OSs and it would make it difficult, not entirely impossible, but difficult to decompile.
The trouble would come from learning how to access native code from Java as much of the documentation is not helpful or just simply nonexistent. This would utilize the Java Native Interface (JNI) which allows Java to, well, interface with the native (compiled C/C++) code. This would make it possible to create a Jar file that would effectively become a Java library for you to access throughout the rest of your project. The native code, however will still need to be loaded at runtime, but that's apart of learning how JNI works. A helpful link I found for JNI is http://jnicookbook.owsiak.org/ (for as long as it's still a functional link).
One of our clients here where I work has a project written in Java and needed to implement our code that is unfortunately all written in C. So we needed a way to access this C/C++ code from Java. This is the way we went about solving this issue without rewriting our code in Java. But we had the benefit (?) of having already written our code in C.
This solution to write a bunch of extra code last minute in another language that I may or may not be familiar with doesn't sound like particularly fun time.
I would be curious to learn what possible problems others might see with this solution.

easiest way to refactor code from Objective-C to java?

I am an iOS developer and my entire career, to date has been spent using Xcode, along with Objective-C and C code, to write apps for the Apple app store. I would like to refactor my code to java and/or xml using Eclipse and try getting a few of my existing apps on Google play.
I understand that even though both languages are object-oriented, one (Objective-C) is compiled and the other (java) is interpreted. Does this present any barriers to essentially refactoring the code file by file, line by line?? What about the C functions? Will they work in Eclipse?
Is there some kind of translator that will automatically convert Objective-C to java, or translate Xcode files to Eclipse files????
Yes, you can translate a file in Objective C to Java line by line using this framework in your Android Project:
http://github.com/rcmcastro/cocoatouch-for-android
But you will need to create the UI, because it's totally different. But the logic, the architecture and everything else will be the same and will work just translating the files and run the app.
The Android and iOS platforms are significantly different, so trying to port an app, line-by-line is going to produce an app of very low quality. To be honest, it's not really feasible because of the vast differences in APIs. The more "interesting" the app (in other words, the more it does), the more trouble there is in porting it. Beyond API differences, there are fundamental differences in the philosophies of the two platforms that will cause major re-design of functionality, not just code.
That isn't saying that apps should not be written for both platforms. Many apps are indeed available for both. But it's not a trivial or automated effort unless you started out with a cross-platform mobile development framework (for example, see this answer). Moving an app to a new platform requires redesigning the app to fit that platform before you even start looking at the code.

How to write Python middleware for Java/Scala backend? How to connect Java and Python?

Let's say I've got a Java/Scala backend and I want to develop middleware in Python for it. I have no experience with developing middleware, but I presume it means that from within Python I would need to issue commands to the running Java/Scala backend programs, and in turn receive feedback from that backend. For this to happen I need to interface the two languages and there are several options for interfacing Python and Java. According to these pages there are some options:
JPI
JNI
JPype
Jepp
Jython
JCC
Unfortunately, JPI, JNI, JPype and Jepp do not seem to be actively developed anymore (last update more than a year ago). Jython is still active, but I read that it is not possible to import all Python modules from within Jython. JCC seems to be some kind of C++ layer between Java and Python, which also seems counter intuitive.
I've also found some questions on SO about the topic, but most seem more than 3 years old, which in internet/Python land is of course a long long time.
Since I've got some experience with the ZeroMQ messaging library I could use that, but I'd have to adjust the Java programs for it (which wouldn't be that big of a trouble, but if there's a better solution..).
So my question is: taking into account that I have control over a Java/Scala backend, what is currently the best way to write a Python middleware layer for that backend?
You haven't given a lot of details about what you're trying to do. If your middleware runs in a separate process then it probably won't make a lot of difference what language your middleware is written in as long as they can talk to each other—and you can do that with ZMQ as you suggested.
If you're actually just making calls into Java/Scala libraries from a layer you're wanting to write in Python, I'd go with Jython. "Not being able to load all the modules" is only an issue if you were planning on using some of the modules that aren't available. Even for those modules that aren't available, you should be able to find suitable Java substitutes you can call.
Finally, if you really want to directly interface between Python and Java, you could look into Babel. I know some people who have used it for interfacing C, Java and Python programs successfully, and it seemed to work quite well for them.

My Java GUI interfaces with my uber-cool proprietary dll. How can I prevent 3rd parties from interfacing with this dll?

I'm writing my process in C++.
Now I want to write its GUI.
I was thinking of using Java in order to do this and link it using JNI, but then I thought of a security problem...
Suppose I have my GUI.exe file written in Java, and I also have my Engine.dll file written in c++.
What would prevent evil evil people from taking my DLL and linking it to their program?
I do use a license validation stuff in my C++ dll, but it can be broken by these evil evil people.
I know every program can be cracked, but I don't want to just GIVE them my engine for easy use.
Is there a way to secure this link?
Or should I use C++ for writing the GUI as well?
The most portable solution probably involves encrypting the data entering and leaving your DLL by whatever means seems appropriate. Obfuscation of the C++ side isn't necessary at that point. This would require the encryption keys to be embedded in both the C++ binary and whatever you are compiling your Java to; you could take extra steps to make this inconvenient to find by hiding it with a large slab of random junk and indexing into it, for example.
Another alternative is to pay up for a licensing system that would be checked at call or link time by ubercool.dll.
Ultimately you're trying to perform a bit of a doomed defensive action. If your ubercool function is genuinely valuable or useful and someone wants to use it in ways you'd rather they didn't, they'll work out how. Can anyone think of any commerical software that hasn't been cracked?
Lastly, you can run your software on a system which is impractical for the end user to fiddle with. Mobile devices with locked bootloaders, TPM modules and so on are one way to do this; the other is to run your ubercool stuff as a hosted service to which people may connect if they have appropriate credentials which you can of course control.
Consider using obfuscator for your Java or C# code that will use your dll. This will not solve all the problem, but it will be more difficult to reverse engineere your programm.
Also, if your project is written in C++, you may consider using C++\CLI for your GUI part of application.

Run Java in your web browser

Is there a way to run a Java command line in a web page along the lines of this Ruby web page:
http://tryruby.org/levels/1/challenges/0
The aim is to be able to give complete newbies a very simple introduction to the language without having to worry about IDEs, compilation, etc.
Well, since Java is a compiled language and has no REPL, there is no such "command line". But I can think of theoretically possible ways to implement the idea.
An Applet might be not really a solution. I don't know how far you can get with limited permissions. Security concerns might allow you to only operate in a sandbox and / or not to compile / execute code.
A Java WebStart application might have such permissions. It would be a similar task to provide a slim IDE. Or making Bluej run from WebStart.
Provide a web application that simply files a request to a server which compiles and executes the code and returns the result. I assume (I'm not sure) many online REPL work like this. (By skimming the JavaScript of try python I think it files AJAX requests) But then there's still a security concern, like what if a programm begins to randomly remove files? Google Appengine has advanced security mechanisms to prevent missuse. To implement them for "try java" it would require advanced effort.
Next idea is to limit everything down to a subset of the Java language. For providing a small introduction, a little tutorial with predefined answers and maybe a bit basic math you could write some JavaScript on the client side to decide wether the learner's answers are correct or not.
Don't forget that web-based IDEs are currently developed, for instance Eclipse Orion. Maybe you could watch these projects evolve and use them for such purpose. Currently I've only seen JavaScript code edited in there, and executing JS is one of the webbrowsers natural capabilities. I don't know which programming languages they are going to support or if code execution will be supported.
But usually java needs to be compiled to be useful to a JVM. So I am not sure you can do anything like that that would be useful for java. The key difference is in the interpreted (Ruby) vs compiled (java) implementation.
See What's the difference between compiled and interpreted language?

Categories

Resources