aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes c/c++ from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "c/c++ from Java" Watch "c/c++ from Java" New topic
Author

c/c++ from Java

Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

Does anyone know how to run c/c++ code from Java program.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I am certain that this is not part of the SCWCD certification (which this forum is all about)

The JNI API can be used to call C/C++ code from Java.
Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

I used the JNI but it shows me an error as can't find the class file. Means when I compile the .java file it creates the .class file with no error or exception but when I try to make the header file using "javah" it is telling that he couldn't find the required class file. I placed .java and .class file in the same directory.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
You might want to work through a JNI introduction like http://www.ibm.com/developerworks/java/tutorials/j-jni/ or http://www.javaworld.com/javaworld/jw-10-1999/jw-10-jni.html. After that, things should become clearer.

PS: Strange URL of this topic: ".../java/java/java". SEO at work?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
java.lang.Runtime.exec("C:\\Programs\\MyCPlusPlusProgram.exe");
Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

Thanks Jimmy. Thanks everyone.
Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

@Jimmy:
When I run the code using the Runtime object as you said it gives me error telling that


C:\WINDOWS\system32\ntvdm.exe
Error while setting up environment for application. Choose close to terminate the application.

I am running the program on windows XP and I used TC compiler for the C program. Please tell me what is the cause.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: c/c++ from Java