Want to create animation dll for Window XP
Is it ok to create Java2d animation and export as dll??
Yes. You need to write code in C++ to start the JVM with the invocation interface to JNI, and call into it. However, you may find it difficult to create windows in this way that integrate seamlessly with your Windows environment application to display your animation. This is a rather advanced JNI usage, and I'd recommend reading the JNI book before even trying a little bit of it.
I am pretty sure you can only create .Jar files from java not dlls
I doubt so, unless there's some 3rd party tools out there. For your case where graphics is involved, chances are even lower.
Actually, what Quentin said should work. When you compile java to native with GCJ you first compile the .java files into platform specific .o (object) files. Presumably you would compile the .o files into a dll rather than an exe. GCJ also includes components like the garbage collector, and base java libraries. None of which require a JVM to run. The downer is that the dll would be huge. A simple "Hello World" app when compiled with GCJ is ~35MB, thanks to all the default libs and the garbage collector. Likewise your dll would be huge.
There are "bridges" that allow Java and non-Java code to call into one another. Depending on what you are trying to accomplish, these might be useful as you could write your Java code and then call into it from a C++ or C# DLL, depending on which language you are creating your DLL with, which will also determine what kind of bridge you need. I have never seen a freely provided bridge though. All the ones I've found when looking had to be purchased.
No, IIRC you can't. DLLs are linked directly when loaded. Java code needs a jvm, so you can only provide a dll that starts a jvm and starts code there, but not all necessarily stuff fits in the dll.
You should not do this. It looks like you're trying to use the wrong approach for your problem.
Well…
GCJ is available for Windows.
GCJ is part of GCC.
GCC can create dlls.
It might be possible to put that together to build DLLs using GCJ.
Yes, it is possible to generate DLLs from Java source code.
2 Methods I have used:
IKVM
Graal
IKVM is mature, but rather slow in runtime execution of the generated DLL.
Graal is fast, but early days and immature in the Windows environment.
See https://openjdk.java.net/jeps/295 for further info.
There are other commercial options available as well.
I agree with bmargulies. It's probably feasible for an expert, but it would be a large DLL and you'd be mixing technologies that were never made to work together. It doesn't make sense to try this, in my opinion.
Related
Just wondering if there are any Java implementations that work without a JVM. The reason I'm interested is, well, simply because I'm curious, and I was wondering if there were any "lightweight" Java implementations (without all the Sun libs attached).
I'm also interested in embedding Java in C++, but embedding the JVM in C++ seems rather ridiculous to me. I just want to exploit some of the Java language features in my C++ apps, but not exploit all the frivolous Java APIs.
EDIT:
I see from a lot of the answers I've gotten that I need to clarify...
I recently got in to developing node.js applications, which uses JavaScript. JavaScript in istelf is a language spec, it doesn't automatically come with the DOM, window.open, etc., although it did for a while. I'm wondering if there's something similar to Google's v8, except not for JavaScript, but for Java. In the end, I don't care if I can't write Hello World apps with it, I just want to be able to embed Java in a C++ application the way I can embed JavaScript in a C++ application with v8 or SpiderMonkey. If I could do that, then I could implement console output in C/C++ and then make that implementation callable from Java.
Do you want the Java VM alone without the API(STandard Library) ?
The JRE is composed by the JVM (Virtual MAchine) and the Standard Library, I have doubt that you can find a java implementation without the JVM ... You could find a compiler that compile java source code into native code(take a look at GCJ), but not a Java implementation without the VM.
Take a look at this wikipedia page to see some alternative Java implementations .
There's GCJ (GNU Compiler for Java), but the project has been deprecated since OpenJDK was open sourced.
there are light weight java processors designed for use in small devices for example JOP
As others have hinted, the "JVM" is the mechanism that knows how to load classes, interpret "bytecodes", and manage storage. It does not inherently include any of the java.lang... stuff, except that a few classes (String, Class, et al) are needed to represent classes and other basic data structures in the JVM.
As a result, Java without a JVM is just a bunch of meaningless bits.
There are (or were) compiled versions of Java that do/did not need the interpreter (though a reasonably compact interpreter is quite easy to build). A primitive class loader and some sort of storage management are still necessary, but class loading can be kept simple and for short-lived apps (or those that live with special restrictions) the storage manager need not do garbage collection.
As pstanton suggests, there are "lightweight" Java (or "Java-like") implementations that are suited for small devices.
IMHO, You need to re-exampine what it is you really want.
Java runtime consists of two main components
The JVM to run the code
The standard libraries which come with it.
You suggest you want to use Java, but you don't really have anything left without these.
For example, you cannot even write a "hello world" program without the libraries as String is a class in the JDK.
Sorry for the stupid question, I'm just beginning to learn Java. Can it be compiled into a .exe to be run on another computer, or is it only for computers with a JVM?
Not exactly. You can bundle a JRE with your executable, which is kind of like the same thing. Embedding a JRE is one approach offered by launch4j.
There are third party projects that will allow you to do this. A free one is http://gcc.gnu.org/java/ . I don't believe it's officially supported by Java though, but it's also gnu, who happen to know a thing or two about compilers.
There is also http://www.excelsior-usa.com/jet.html which is a paid product, but supports up to Java 6.
Can you make candy without sugar?
Yes, you need to have a JVM (just the executing for compiling) to run and to compile.
Although, it is not necessary when trying to write just the code.
Do they use something like Mono's PInvoke? Or is it more like internal calls registered before the runtime is started? Does java have a base library for handling native calls like mscorlib.dll? If I want to invoke a JVM in C code will it libraries look for the .so/.dll files? Does it make a difference to Java standard libraries if I statically link all of the JRE natives libraries?
They use JNI, exactly as it is publicly documented, to invoke native shared libraries for the specific platform.
As far as invoking a JVM from C code, the JVM uses shared libraries (DLL, SO, etc). A quick search of the JDK 6 source code does not reveal any System.loadLibrary() for the core native support (like native methods in Object, String, etc). That suggests to me that the native code for these methods, which appears to be in DLL's judging from the contents of the JRE/bin directory, is explicitly linked by java.exe (and javaw.exe in Windows).
When I last looked at this stuff, the requirements for invoking a JVM from C code was a well documented part of JNI - I strongly suggest you refer to that doco to proceed further. We even went so far as successfully writing a native C wrapper/loader for the IBM AS/400 Java 1.1 JVM.
They use the Java Native Interface (JNI).
I've never called the JVM from C, so I don't know about that.
There is an example here about how to start a JVM from inside your C program:
http://www.inonit.com/cygwin/jni/invocationApi/c.html
"Java Native Access (JNA) provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java code" (quotation from their homepage).
Personally never tried it so far.
First, I have no experience doing this. But like the beginning of any good program, I have problem that I need to fix, so I'm willing to learn.
So many of you are probably already familiar with pdftk, the handy utility for handling various pdf-related tasks. So far as I can tell, most of these features are available in much newer, lighter libraries/extensions, except the one I need (and probably the only reason it still exists): merging form data files (fdf and xfdf) with a form PDF and getting a new file as the output.
The problem is that my server doesn't have gcj, which is fundamental to build/compile pdftk. I don't know if it's because I'm on Solaris or if it's for some other sysadmin-level reason, but I'm not getting gcj anytime soon. And there are no pre-compiled binaries for Solaris as far as I can find.
So I'm thinking that the MAKE file and C code can be rewritten to import the Java library (very ancient version of itext) directly, via javac.
But I'm not sure where to really start. All I know is:
I want a binary when I'm done, so that there won't be a need for a Java VM on every use.
The current app uses GCJ.
So my first thought was "Oh this is easy, I can probably just call the classes with some other C-based method", but instead of finding a simple method for doing this, I'm finding tons of lengthy posts on the various angles that this can be approached, etc.
Then I found a page on Sun's site on how to call other languages (like C) in a Java class. But the problems with that approach are:
I'd have to write a wrapper for the wrapper
I'd probably be better off skipping that part and writing the whole thing in Java
I ain't ready for that just yet if I can just import the classes with what is already there
I'm not clear on if I can compile and get a binary at the end or if I'm trapped in Java being needed every time.
Again, I apologize for my ignorance. I just need some advice and examples of how one would replace GCJ dependent C code with something that works directly with Java.
And of course if I'm asking one of those "if we could do that, we'd be rich already" type questions, let me know.
I'm not sure what you are looking for exactly, so I provided several answers.
If you have java code that needs to run, you must:
Run it in a jvm. You can start that vm within your own custom c-code, but it is still using a jvm
Rewrite it in another language.
Compile with an ahead-of-time compiler (eg gcj)
Incidentally, you could compile a copy of gcj in your home folder and use that. I believe the magic switch is --enable-languages=java,c (see: here for more)
If you have c-code you want to call from java, you have four options:
Java Native Interface (JNI). It seems you found this
Java Native Access (JNA). This is slower than JNI, but requires less coding and no wrapper c-code. It does require a jar and a library
Create a CLI utility and use Runtime.Exec(...) to call it.
Use some sort of Inter Process Communication to have the Java code ask the c-code to perform the operation and return the result.
Additional platform dependent options
Use JACOB (win32 only: com access)
I am not sure if I understand what you are looking for.
If you are looking to incorporate the C code into Java to make a native binary without the gcj, I think you are out of luck. You can include the C in Java, but it would be a primarily Java program meaning you would need the JVM on each run. Is there anything stopping you from compiling the gcj yourself?
I've been charged with creating a little GUI launcher app to go on a CD which will offer the user some software and some videos. It's not being aimed at particularly tech-savvy people, so it needs to be quite simple. I guess the real sticking point here is that it will be form based.
I would very much like the launcher to just run from an exe without having to install any .net stuff or have java installed. I know ClickOnce is fairly simple and I will fall back on it if necessary, but I thought it might be worth asking if there are any easy ways to do this.
I mainly program using visual c# these days, but have experience with java and c and I am a relatively quick learner, so feel free to suggest other languages.
The most straightforward way to create a dependency-free executable for Windows is to use ordinary Win32 functions from C (or C++). Alternatively, you could use MFC with C++ because you can link MFC right into your executable to avoid a dependency on MFC DLLs.
There are probably other C/C++ frameworks that can be linked into an executable. However, you probably want to avoid Java and C# or any other .Net language, if you want minimal dependencies.
Depending on the minimum target OS, you could possibly choose VB6, if it doesn't affend you too much, because the VB6 runtime has been included in windows since Windows 2000. However, you need to stick to the included controls to keep things simple.
If you write it in Java you could bundle the JRE on the CD and just have a batch file that uses that bundled JRE to launch the app. This should work, but the JRE is kind of large, so you'd need to make sure you'll have enough space on the CD for it.
.Net might be able to do something similar but I've never looked into it at all.
The simplest thing would probably be to just write a simple native app in C/C++ (or in some other language that compiles to a standalone EXE) and use that.
Just statically link to the C runtime library and any others you might need (like MFC): /MT or /MTd on the command line and Project Properties > C/C++ > Code Generation > Runtime Libraries in Visual Studio.
You can use C++ with wxwidgets for GUI and statically link your application
Now all the windows OS (from win 2003) pre installed with .Net frameworks... so you can go ahead and code in any CLR language...
You are saying ur clienats are not tech ppl, so the chances for uninstalling .net frameworks from their machine is very low..