Is there a quick way (e.g. tool) to detect, from the source (or maybe even from compiled classes), which parts of an application call Java API methods that are only implemented in a specific Java version? (e.g. which parts of my app are Java6-specific)
I don't necessarily want to hop through all ClassMismatchErrors and avoid the trial-and-error-method. Let's say I only want to document which parts of an application won't work if they were writte for, e.g., Java6 and I want to run it in a version 5 JDK.
Is there something like this? Google did not help this time, nor did I find any solution here (a rare case indeed:)
The Animal Sniffer might be helpful for this, especially its Maven plugin.
If I understand you correctly, what you're describing doesn't sound like a very good idea to me.
It sounds like you want to build some library on JDK 6 (specifying -target 1.5), but let it be run on JDK 5 and just have certain classes or methods here and there just not work (because they needed a Java6-only API). I wouldn't do this. A method which should work might still trigger a class to be loaded which itself contains some reference to a class that's new in Java 6, and an Error will be thrown.
It's much better if you just choose which version is your minimum supported version and live with that.
Related
I am trying to use Vowpal Wabbit through Java. I have downloaded and successfully compiled the code from GitHub. The command line tool works fine.
After having a quick look at the repository (especially here), I can only assume that using it through Java is supposed to be already possible, and I don't really want to reinvent the wheel.
A wrapper around Vowpal Wabbit that allows use through Java. This wrapper is designed to be self contained. Because
of the use of JNI, a number of platforms are supported in this JAR.
I have added the maven dependency (found here) to my project, but without any kind of document, I don't really know where to start.
I have seen in another question that it seems to be possible to use VW with Java, but the guy only uses Runtime.getRuntime.exec() to call his bash command, and I can't find any documentation about any other way of doing (and there are only 2 questions mixing VW and Java on SO, which doesn't help).
I am new to JNI, so most likely there is something easy that I don't see.
To be perfectly clear, my questions are :
Should I just make a valid vw command and use it through Runtime.getRuntime.exec()? This doesn't seem to be the spirit of JNI, for there is no need for any wrapper/library for this. Plus, this doesn't make it very portable.
Where (the hell) is the (Java API) documentation ?
Any kind of help or guidance would be welcome.
I was one of the two primary authors of the VW JNI wrapper. Since the posting of this question the interface has significantly changed. We now encourage users to compile the native side on their own and provide it on the java.library.path. We have updated the README significantly to show how to use the library from Java.
I totally agree with your criticism that we have not published the Java API. I will work on that the next time I modify this code. In the meantime please feel free to clone the library and run mvn install and you can generate the Java API docs yourself. They should be quite detailed as we spent a lot of effort writing detailed docs.
You may checkout vowpal wabbit JNI wrapper we've built in Indeed: https://github.com/indeedeng/vowpal-wabbit-java.
We wrote integration test that can work as usage examples and we wrote API documentation as well. Check "using the library" section of README.
Hope this will help.
I don't think this adds a lot, but none of the previous answers really provided a clear answer. Like #Macchiatow mentioned, to use the Java wrapper which comes with Vowpal Wabbit, you would:
(on the project root dir) make all java or make java
cd into java and verify the installation with mvn test
you'd then mvn install to have the Java API jarred up and placed in your local maven repository. Supposedly this builds the JNI parts on your machine, so as to fit the C/C++ libraries of your platform if you have the necessary native C/C++ libraries installed and available to the make command.
you'd supposedly be able to include the vowpal package/s from those jars in the build tool used in your own project (ant/maven/boot/leiningen/sbt/etc. as in here).
For more background maybe see the Vowpal Wabbit Java readme. I think what it tries to say there, is that if you want a ready made jar from maven central, you should make sure it's the same vowpal version you're using, but without knowing more I'd guess if you built it like above, you are by definition using the same version.
I've had the above process work off a fresh clone, with Ubuntu 16.04 and Java 8.
This link may be of some help with regards to setting up a JNI wrapper.
I wasn't able to find Java API documentation anywhere, but Java code seems well documented - did you maybe try generating Javadoc yourself from the code?
There is indeed Java JNI wrapper to have a basic access to VW. By basic I mean to teach your model and to predict probability later on. They also provide Python library that can do far more than wrapper for Java. Recently I was forced to expose few more VW methods to Java by extending code provided.
Back to the questions:
Rather use the vw-jni artifact available in central maven repo and clone their code and run make all java. I some cases compiling code yourself will be the only solution, as for example provided artifact won't run on OpenSuse (my case)
Code available pretty straight forward. VWLearners::create is a factory to get an instance of VW from Java.
I came upon this simple Library that someone wrote in java GetImageText.java for OCR in images so i tried compiling it on my Ubuntu via terminal but i get several error as shown below in this paste :
Compilation Errors
Can Someone help me with it , it is absolute necessity that i test this code , its explanation can be found here
I think the problem is that i do not have com.sun.image.code.jpeg in my system, although java is definitely installed. Although I am not sure how to import this package without using an IDE.
The problem is that the library you are trying to recompile depends on INTERNAL classes1. Portable libraries are not supposed to do that!
What has happened is that the class has been removed or replaced. This happens from time to time, and that is the reason that people are not supposed to write code that depends on INTERNAL classes.
Solutions:
Bug the authors of the library to fix the problem.
Figure out which version(s) of Java that the library supports, and stick with those.
Find an alternative library that supports the version(s) of Java that you need.
Non-solution: Compiling the library on an older version of Java and running on a newer one is likely to fail. The class needs to be present at runtime, as well as at compile time.
1 - Anything in the "com.sun" tree counts as INTERNAL. Sometimes people have no choice but to have such a dependency. However, they still needs to deal with the potential consequences for portability.
I want to ship an open source Java project with its own JRE so that it doesn't depend on whether one is installed or not.I will have everything in one directory and my program will be the sole user of that jvm and class library.
As Java is now open source, I think I can now legally strip down the class library (rt.jar) to only classes I need. For example I don't use any SQL so I don't want to burden the download with classes in the java.SQL package.
This would be somewhat analogous to a linking step when an executable is built from libraries using only methods in the call tree that starts with the programs main().
Does anyone know what tools I might use to do that. Is it possible?
I think this is pretty much already done in Java 6 update 10.
It was planned for Java 7 but it shipped before.
It is the Java Kernel here are the details, I'm not quite sure if is what you need.
Here are the links:
http://tech.puredanger.com/java7/#kernel
http://weblogs.java.net/blog/chet/archive/2007/05/consumer_jre_le.html#JavaKernel
Here is other:
http://java.sun.com/javase/6/6u10faq.jsp#JKernel
There is a commercial tool that can legally strip down the Java class library.
As the title suggests, we have a Java (Swing) desktop application, and we'd like to be able to have some basic access to the Jump Lists (in the new Windows 7 taskbar).
In particular, we'd like to be able to add some "user tasks" to the jump list--the ability to start other modules in our application, maybe to close all running modules, etc.
I know that we could do this using JNI or JNA and the C API described here, but that is our option of last resort. I'm hoping that there might be an easier way--something that Sun has already implemented, or maybe a third party library or something.
Google is no help so far. Anyone else have any ideas?
There is a Java library providing the new Windows 7 features for Java. It's called J7Goodies by Strix Code. You can create your own jump lists with it. Of course it supports "users tasks" too.
This would break compatibility with other systems so Sun almost certainly won't do it.
There are a handful of desktop/toolbar integration libraries out there that make the jni calls for you, you might look for one of those that has been updated for windows 7, but if you are going to go single-platform, why not use C#? (Not that I'm a fan, I'm 100% Java, but if you're already breaking compatibility you might consider going all the way just for ease of programming)
Is there any solution through which I can convert java'a higher application, created in netbeans IDE 6.5.1, into lower version of java version 5.
If you have the source code, which I assume you do, this might be easy or difficult depending on the code.
Java 6 made few language changes over Java 5. The only one that springs to mind is you can put #Override on implementations of an interface.
The bigger issue is whether you use any of the API differences, of which there are several. I think JDBC has some major differences, which you may or may not use.
These issues may be big or small. It's really hard to say without knowing anything about your app. Generally speaking though they should be small.
Otherwise you should mostly just be able to recompile it with a Java 5 compiler.
If you don't have the source code it's still doable but you just need to disassemble it first and fixing any issues may be tedious.
You can simply try to recompile it for Java 5. As no language-changes are made between version 5 and 6 you can only run into problems, if you use APIs added or enhanced with the version-upgrade.
If you have the source, you could use backported libraries and code rewrite. There is a tool called Retroweaver which can convert 1.5 code to 1.4, but I doubt It works for 6 to 5.
there is an option somewhere to tell Netbeans to generate GUI with non-Java 6 classes. It is documented somewhere, sorry I don't remember. I've already switched to Netbeans 6.7 (RC3).
Check also usages of Desktop API, #Override in implementing interface methods, etc.
It is a good practice to build with a JDK5 in a CI server (like hudson).