I have function in Matlab which works perfect. I got p from m file and it works on some computers, but not on every (even I did it in 6.5 version). I simply didnt know what to do, and wrote the same program in Java. BUT, the results are not allways the same, and sometimes program dont works in Java. I cannt find the mistake in Java (I know that Matlab's function is relevant).
I have two (dependent) questions:
How to make my Matlab code safe from hacking and working on every computer?
How to use Java to protect and run my Matlab code (againg on every computer)?
Is there solution for this or what?
How to make my Matlab code safe from hacking and working on every
computer?
If by 'safe from hacking' you mean protect from decompilation of your java class(es) than have a look, for example here or many other similar questions at stack overflow.
How to use Java to protect and run my Matlab code (againg on every
computer)?
Officially you cant execute matlab from withing java, although opposite is supported. However, you can use external tools e.g. matlabcontrol. But there can be licence issues if you start doing this. So be vary of that.
Related
I'm currently working on a simple Java project where I wanted to test if DRM in java is possible.
I had different thoughts about an approach to this topic.
My last idea was about running java code without having the source or any physical copy of the program on my machine. So, for example, I have a Program on my machine that kind of downloads the compiled classes into memory and then runs it from there.
I know that this is possible in other languages.
My problem is that I don't know if this is possible at all and if so what I have to search for? I already googled my question in several ways but not received an answer that was helpful.
Maybe you can tell me if the way would work at all and what I have to search for then.
If you have another approach for DRM in Java I would be grateful if you let me know.
I want to access Java library within Ruby, in example Kafka already give jar for every operation, what things I need to do if I want to use it from Ruby?
Like maybe I just need to run shell command to run the Jar within Ruby, or do I need to port the library in Ruby? If it comes down to porting the library, how to do that too?
Thank you in advance
PS: The Java, Ruby, or Kafka are just examples. What I need to know is the big picture how to porting a library. Of course if you add some code example too I'll be more than happy :)
I agree with Aetherus that the fastest and most convenient way is to use JRuby. However I believe there other options than communicating with external Java processes. What to choose probably depends on what code you want to call. I see at least two other options.
Wrap the Java code you want to call in a main program and call it on the command line. This will be slow since Java needs to start and that takes forever but may be a fast way forward in some cases.
Call the Java code from C code that you compile with your Ruby. This will still need to load the JVM but you could probably make it happen only once. I found an article outlining how to get around doing it with JNI.
Both these paths will probably cause you a lot of pain but if it is important to stay on MRI it may be worth the trip. Have fun!
With JRuby, you can import the jar file, then include the classes you need in that jar:
require 'java'
require '/path/to/your.jar'
include_class 'com.really.long.ClassName'
But with Ruby implementations other than JRuby, you have no choice but to communicate with external java processes (through socket, IPC, kill, ...).
I need to be able to get input without the user pressing enter in java. As far as I can tell this cannot be done without JNI/JNA which I would like to avoid. So I am looking for a small program that could do this for me and then undo it when called again (with different arguments maybe?) It can be in any language (preferably a compiled one), but preferably it could be compiled without MS visual studio because I would rather not install that.
Basically is there a windows equivalent of stty raw that I could call from Java?
You will definitely still need JNI. Many libraries already exist for this however. You can try JCurses here: http://sourceforge.net/projects/javacurses/ however it has not been updated in a 3 years!
I believe if you are on UNIX/Linux that Lanterna (https://code.google.com/p/lanterna/) also has something for this purpose (and it's also a lot more up to date and easy to use).
I don't think anything more specific and lightweight exists without you having to write one yourself.
I wrote a command line tool in Java and it gets run many times in a row from a BAT script. Right now it's a runnable JAR (which in hindsight isn't probably the right choice here...). The JRE seems to get loaded and unloaded every time the program is run, which seems inefficient. Overall, it seems a lot slower than it should be.
Do any Java gurus out there know a more proper way to handle this situation?
As there is no easy fix, you might also consider more radical approaches:
Actually porting what's in your bat in the java itself (easy if it's loop on files with some kind of filter).
Compiling the jar into an exe (e.g. with GCJ) if maximum portability is not an issue.
You could try a number of things. A simple one is starting the JVM with -Xquickstart.
EDIT: Looks like this option is for the IBM JDK only (which incidentally also has support for AOT-compilation/shared class caches).
Another option is, making it into a single longer running process that can accept multiple jobs interactively or in a batch.
Someone created a project to make a framework for this purpose called nailgun, not sure what state it is in. Google gave me these results when I searched: http://sourceforge.net/projects/nailgun/ and http://martiansoftware.com/nailgun/.
There is also a GNU's gcj which will compile Java down to native code http://gcc.gnu.org/java/.
This is actually one of the biggest problems with Java, and there aren't any easy solutions. Basically, if you want a lightweight program that might get run many times in rapid succession, then you shouldn't be doing it in Java.
I don't have any experience with compiling Java to native code, but I do know that almost no one does it; there might be a good reason for that.
If you post the BAT file, or at least describe what it does, maybe someone can offer a better suggestion.
I am an iOS developer and I found a great library that handles all kinds of astronomy related calculations for me. The problem is that it's written in Java. Although I have enough experience with languages close to Java, I can't run Java on iOS.
I'd like to port it, but being that I've never ported anything before. Like I said, I don't think language will be the issue. It's a fairly simple library, involving mostly Date objects and math.
I'm trying to figure out the best way to do go about porting. Do I start with the core methods/functions of each class, or can I just go line by line in each file until I have translated everything?
Just start wherever you please. Generally, you'll want to start near the core, and work your way out. Just remember these three steps:
Make it work
Make it right
Make it fast/clean
So don't worry about getting it looking pretty or anything right off the hop, just get it working how it needs to, test it. Then look at where you can refactor if possible, etc.
Since this seem to be a library of functions, it would not depend on any platform specific functions.
Porting this should really be straightforward. You can port function by function, maybe start with functions that are important for your app.
The really tricky part (given it's a math lib) will be assuring that it works correctly: you should have the same set of unit tests as original lib. The best would be to create a java wrapper classes that call your lib via JNI so that you could run original unit tests on your lib. Pure Objective-C lib (no platform bindings) should run on both OS X and iOS, so you can run tests on OS X. Do something like this:
Look at original Java lib, and create functionally similar API in Objective-C: Same classes, same method names.
Take the original java classes and replace all content of methods with JNI calls to your native library.
Implement functionality in your lib.
Run java unit tests (which now calls your native lib) to make sure your lib works correctly.
For easier JNI development you can use JNA or any other JNI wrapper listed here.