| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
The java source code in Simple.java can be compiled just with:
javac Simple.java
C++ header and sources could be generated with:
java -jar ../../target/java4cpp-1.0-SNAPSHOT-jar-with-dependencies.jar -c Simple
The generated files include:
The file use_simple_java.cpp contains the C++ example source code using the generated files with a main method.
Using any C++ IDE or build environment add the JDK include directory and its operating system specific subdirectory to the list of directories searched for header files, the JDK's lib directory to the directories where libraries are searched. Add the jvm library to the link options. Ensure that the class file is on the CLASSPATH and the dynamic jvm library on the list of directories searched for dynamic libraries.
The following instructions were tested on an x64 Windows 7 computer with Visual Studio 2010 and JDK 1.8.0_60 for Windows(x64). Please adjust paths and settings locations as appropriate to match your system. All settings are merely suggested. Once you have a working setup feel free to experiment with the alternatives.
The Simple sudirectory contains the Visual Studio solutions and projects generated.
Close Visual Studio if it is open so it will get the next environment setting change.
Add the location of jvm.dll which comes with Java JDK to the Windows Path.
(Re) Open Visual Studio
On a system where the JDK was installed in:
/usr/local/jdk1.8.0_60/
The program can be compiled with:
export JAVA_HOME=/usr/local/jdk1.8.0_60/;
g++ -I ${JAVA_HOME}/include -I ${JAVA_HOME}/include/linux -L ${JAVA_HOME}/jre/lib/amd64/server/ -Wl,--rpath ${JAVA_HOME}/jre/lib/amd64/server/ use_simple_java.cpp simple0.cpp -ljvm -o simple
Then run with:
./simple
This produces the output:
s.getValue() = 4
The C++ application has successfully run passing an argument to a Java class method and recieving a return value from a Java class.
| Back | FazBrowse Home | New Git URL |