AIR 3 Native Extensions - for Java on Windows? - apache-flex

There are a lot of tutorials/details on writing ANE's for Java on Android, but not for Java on Windows. Is it possible to do this?

To package Java code in a native extension on Windows, you would need a C wrapper (using the JNI invocation API). You might need to distribute a full JVM (though depending on what you know about your target machines, you may be able to assume a JVM and JAVA_HOME defined).

Related

Include 32-bit library into an existing 64-bit application

I have a existing 64-bit Qt Linux project (C/C++), now I wanted to add additional hardware. Unfortunately the hardware vendor provides a SDK with 32-bit binary-only C .so.
Just including the library leads to an error like this:
/usr/bin/x86_64-linux-gnu-ld: skipping incompatible /home/SDK/lib when searching for -example
/usr/bin/x86_64-linux-gnu-ld: cannot find -example
Is there any way to include this library into my existing project?
I found Mixing 32 and 64-bit Libraries in Linux (gcc), but maybe there are some changes as it's already 7 years old.
Thank you in advance!
The x86 and amd64 ABIs are completely different on Linux, so you can't call 32-bit libraries from 64-bit code directly. That said, you can achieve your objective by creating a separate 32-bit program that proxies calls into the library and exposes them via REST, WSDL, Protobuf, or your favorite way of doing IPCs, and then making those calls from the 64-bit process.

How to reduce the size of an exe made from a jar developed in netbeans?

I developed a tool in netbeans and I wanted to make its exe file so I used Excelsior JET.
But the size of the exe goes to 17MB, even though my jar has a size in KBs only.
What should I do to make the size of exe lesser?
You won't be able to bring the size down to KBs with any tool, because your program would still require the services provided by the JVM - threading, garbage collection, JNI, and so on - and, more importantly, the Java standard library. That is a lot of classes, and even the simplest Java program would load hundreds of them (just run "Hello, World!" using the conventional java launcher with -verbose:class).
Specifically with Excelsior JET, you may have an option to use Compact Profiles, a pre-Jigsaw feature introduced in Java SE 8:
https://www.excelsiorjet.com/solutions/java-download-size
But you would need at least the Professional Edition for that.
DISCLAIMER: I work for Excelsior.

Java Compiler multi-platform

How could I compile a Main.Java program to something that I could run with OpenJDK Java 6 or 7 . The program doesn't contain anything besides displaying the message "Hello World"
I would like to compiler to .JAR
Also if I compile the program will it run in Windows or do I got to cross compile like C++ if I'm using Linux as the native developer.
I'm using the Linux Ubuntu OpenJDK Development Kit (JDK)
This is how you compile.
cristian#ubuntu:~/Java$ javac Main.java
but how would you compile to a .JAR file so I can run it in my Windows.
Any guides to learning Java are welcome and thanks for the help.
I'm using Linux Ubuntu.
You must specify your main class in the JARs manifest in order for it to be runnable. You can then invoke your application from it's jar as follows
java -jar application.jar
Current versions of the JDK for Windows will create a file association for .jar files so if you click on them they will execute.
For further details, take a look at Oracle's Jar Tutorial, specifically the section on Setting an Application's Entry Point
Edit
Regarding the need for cross compilation... Since Java compiler targets a virtual machine, you do not need to cross compile for different operating systems. (One of the early taglines for Java was "Write Once Run Anywhere".)
Here is a decent article on the basics of how the JVM does its magic: What Is The Java Virtual Machine & How Does It Work?
The Oracle Java Tutorials are an solid starting point for many things java related and I recommend reading through them if you are new to Java.
Java's JAR files are platform independent and only require an installed JRE/JDK.
OpenJDK does almost the same thing as Oracle JDK however you can also get the Oracle JDK on Linux Ubuntu by using third-party repositories such as ppa:webupd8team/java(details on how to use the repository are provided on the webupd8 website) i found i needed to switch to oracle java for performance issues.
Most common IDE's for java provide support for compiling and packaging to JAR/Runnable JAR.
A popular java IDE is Eclipse(http://eclipse.org) other popular IDE's include NetBeans and JetBrains IntelliJ IDEA.
Most programmers use IDE's for ease of use and other functionality such as IntelliSense(Autocomplete), error checking, Syntax highlighting and debugging.
A good guide to learning java is http://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28. Other guides such as java game development can also be found on Thenewboston's channel or thenewboston website.

Platform specific code

Hope to get some pointers here. I am trying to get QT to compile with slightly different code for each platform. For example,
If platform is Windows then include windows.h
If platform is OSX then include time.h
AND
If platform is Windows use QueryPerformanceCounter function from windows.h
If platform is Linux use gettimeofdayfunction from time.h
The objective here is to write wrapper function to return elapsed microseconds that works with Windows (QueryPerformanceCounter) & Linux/Max (gettimeofday) without having 2 sets of code. Qtimer resolution is inadequate in Windows XP. (about 10-15ms increments).
Anyone can point me to a tutorial on how to do this ? Thank you in advance and Happy New Year to everyone here.
Gary Cho
If this was python, I'd say just create a module that conditionally imports one of the correct modules.
This being C++, I'm fairly certain this isn't possible (I'm not a C++ expert). Even if the compiled binaries were able to run on both windows and linux machines. I don't see any way to compile both windows and linux headers into an executable and then choose between them at runtime.
You're going to need to compile 2 binaries that each include the correct header.

dos command flex core

can i execute some dos like command from flex just like
attrib c:\a.txt -h.
function available in c exec(), in java Runtime.getRuntime().exec().
but in flex is there any available?
I think the closest you're going to come to achieving this is by using fscommand(), which has quite a few limitations.
Remember that Flex applications run in the Flash player (usually within a browser) and thus don't typically have access to shell commands of the host filesystem.
Two of the most requested features for
Adobe AIR have been the ability to
launch native executables from an AIR
application, and the ability to
integrate native libraries into an AIR
application. Unfortunately, neither
feature will be included in Adobe AIR
1.0.
But there is a workaround. It's a bit complicated, yet elegant, and should solve your problem. It relies on CommandProxy, a kit for proxying calls between applications and the operating system. You will find here a detailed article on how to implement this solution
If you want to run batch files using flex..then do the following
var file:File =new File(path to batch file)
//do not give the .bat extension only file name is reqiured.
file.openWithDefaultApplication();
// the batch file will open and run the dos commands you have written

Resources