I am trying to make an XS project in HANA which will use some of the classes and methods that can be found in a .jar file. These classes and methods will do some calculations and present it to the user in the UI.
The question is: How do I access methods and classes of that .jar file?
I have registered it as an external library, but I have no idea how to call it from my XS javascript source files.
there's no way to invoke external .jar package from XS's server-side JavaScript. You can use an external library using function "$.import", but this is only valid for JavaScript library.
XS Server does not and will not support Java. Only Javascript...
If you want to outsource some of your xsjs functions to an external library, xsengine provides a special format for this, called ".xsjslib".
You can import a library using the following code:
$.import("<package_your_library_was_deployed>","yourLib");
access functions inside your lib by this path:
$.path.to.your.library.filename.yourFunction();
Related
I'm aware of all the other questions about this topic, but I haven't found a good solution for my problem. Currently I am trying to use Java code in my C# project. I've already tried to convert the JAR files into .DLL files with IKVM, but this didn't work for me because the JAR files are to complicated to translate into C# because not every component, which were used in Java, can be found in C#. The normal call of the JAR file doesn't work for me either because I need to work with the class instances of the declared classes in the Java code.
Back to my question: Does anybody know how I could use Java code in my project? I've heard that it may be possible to implement Java code like it would be native, is that true? Note that I've to work with the class instances of the classes declared in the Java code.
I highly appreciate any kind of help, sheers!
Edit:
My work around would be that I include batch files, which are calling the JAR files. I will include these batch files into my C# Project and work with the batch files. This may be a even better approach for me because every input and output of the JAR files are done via XML files.
This kind of mixup are not generally a good approach. I think the .Net Framework is very mature and you can find everything you want to do your work.
I would suggest you the following approach :
You can wrap your Java library in a REST API and call it in your C# code. Your REST API can be hosted on an external server or use an embedded server or even a spring boot project.
You can read this post for more details.
I want to make a COM server packaged in a DLL for use from VBA-Excel.
The functionality will be provided by Java classes packaged in a jar.
How do I do this?
For calling Java code from Excel you can use Jinx, the Excel Java Add-In.
See https://exceljava.com for details.
Using Jinx you can write a full Excel add-in including user defined worksheet functions and macros in Java, without any need for COM or VBA.
I'm trying to read a .qm translation files with Java.
.qm files are binary files. I don't have access to the .ts files.
And I don't find much info on these .qm files.
How are they structured ?
Regards,
There's no documentation that I know of, but if you look at QTranslator::load you should be able to follow the format of the QM file.
You will probably need to reimplement QTranslator in Java, as you need not only the ability to load the files, but also to extract and apply translations in Qt fashion.
As per request of OP:
You could use those files by using the Qt libraries and JNI. By using the translator in a c++ dll you can translate strings easily. However, you cannot extract the files or list the contained translations. But if all you need is the actual translation, this solution should work.
I cannot give a real example, because I only now how it works in theory, I haven't tried it, because it's not trivial. But if you are eager to try it out, the general idea would be:
Create a C++ dll and build it against QtCore. The easiest way is to download Qt from their website qt.io. You can for example create a default library project with QtCreator. Note: Besides Qt5Core.dll, Qt requires other libraries to correctly run. They are all included in the installation, but once you deploy your application, those of course have to be includes as well.
Include JNI to the C++ project and link against it. if you're new to this, here is a nice tutorial: Java Programming Tutorial
Create your wrapper methods. Methods in cpp you can call from java that take java strings, convert them to QString, translate them with QTranslator and convert them back.
Load the library in Java and execute those methods
Important:
First, I don't know how java handles dll dependencies. If you encounter errors while loading the dll, it's probably because dependencies of your dll are not present. Second, Qt typically requires a QCoreApplication running in the main thread for most of it's operations. I tested the translator without such an app, and it worked. So apparently for translations only the app is not required. However, depending on what you do in your dll, I think this is important to know.
If you need more details, feel free to ask.
I am making a android project with some native code . running javah results in header files which contain function prototypes with fully qualified java class name in their names. I assume this means that those functions and headers are generated to be called only by the java class which was used to create them using javah.
How do I go on making a native lib that I can use with other classes as well as other projects. Like say I made a library that has a function that I want to use in all my projects then how would I build it so that I can use just the .so file each time without recompiling it for the project. I think we call this dynamic library?
Is it possible? or do I have to create seperate jni headers for each class and then reuse the remaining c/c++ code?
if you want to reuse your native library from various Java projects, you should directly bundle your native library with a Java class that is independent from your initial project.
This way you'll be able to distribute it as an Android Library Project, and use it from your various classes and projects.
I use java Rhino lib as a script engine in my application,
so that users can write their own script to control the application to do some job,
but I don't want them to use the java system lib classes in script ,ex:"java.lang.Sytem.exit()",
does anyone know how to do?? thank you
Call Context.setClassShutter(ClassShutter) on your context with an appropriate ClassShutter implementation that implements the method visibleToScripts(String fullClassName) in whatever way you wish to filter out (or in) whatever classes you want to have be usable from the scripts.