I spent hours and hours on it not moving an inch forward. I have redone the project several times and nothing else is left outside places. Hope someone here can shed some light pointing out some direction.
On Linux Eclipse IDE panel > Run > External Tools > External Tools Configurations:
Name: Dev javah
Tab [main]:
* location: /usr/java/jdk1.6.0_25/bin/javah
* working directory: ${workspace_loc:/Dev/bin}
* Arguments: ??
I have tried:
* Arguments: -d ${workspace_loc:/Dev/jni} com.dev.DevActivity ${project_classpath:Dev} com.pkgpub.DevActivity
which gives me:
1 error
javadoc: error - Illegal package name: "/home/user/dev/Dev/bin/classes"
and also tried:
* Arguments: -d ${workspace_loc:/Dev/jni} com.dev.DevActivity
That gives...
error: cannot access com.dev.DevActivity
class file for com.dev.DevActivity not found
javadoc: error - Class com.dev.DevActivity not found.
Error: No classes were specified on the command line. Try -help.
similarly to -
* Arguments: -d ${workspace_loc:/Dev/jni} com.pkgpub.DevActivity
That gives me:
error: cannot access com.pkgpub.DevActivity
class file for com.pkgpub.DevActivity not found
javadoc: error - Class com.pkgpub.DevActivity not found.
Error: No classes were specified on the command line. Try -help.
But when I run:
which javah
/usr/bin/which: no javah in (/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/android-sdks/tools:/home/user/android-sdks/platform-tools:/opt/android/android-ndk-r7:/home/user/.local/bin:/home/user/bin:/home/user/android-sdks/tools:/home/user/android-sdks/platform-tools:/opt/android/android-ndk-r7:/home/user/android-sdks/tools:/home/user/android-sdks/platform-tools:/opt/android/android-ndk-r7)
The question is... the project is not compiling because javah is not visible to Eclipse NDK, or due to parameter details that something is missing? And in such case, how to get it fixed?
Thanks.
try adding
-classpath bin/classes
as parameter to javah
Specially for Android:
use classes right after bin like project_location/bin/classes, this worked for me on Linux Fedora
javah -d /var/www/project/jni/ -classpath /var/www/project/bin/classes/ com.android.TestClass
#BlackBelt - thanks man for your suggestion!
Here is the parameter that worked, solving the javah side for the compiling process:
-d ${workspace_loc:/Dev/jni} com.pkgpub.Dev -classpath ${workspace_loc:/Dev/bin/classes/} com.pkgpub.Dev
Where pkgpub is the package name, and Dev is the project name. It is worth to mention that the project has the files: \src\Dev.java; \jni\Dev.c; \jni\Dev.h; \bin...\pkgpub\Dev.class.
Now it generates the file jni/com_pkgpub_Dev.h with the right content. Which is great!
However the ndk-build is still not completely linking, and does not generate the com_pkgpub_Dev.c file. So, from Project > Project Build - comes the message:
**** Build of configuration Build (GNU) for project Dev ****
ndk-build
make: *** No rule to make target `jni/com_pkgpub_Dev.c', needed by `obj/local/armeabi/objs/dev/com_pkgpub_Dev.o'. Stop.
**** Build Finished ****
From this message it sounds like some parameter should be missing from the file /jni/Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS := -DHAVE_INTTYPES_H
LOCAL_MODULE := dev
LOCAL_SRC_FILES := com_pkgpub_Dev.c Dev.c
include $(BUILD_SHARED_LIBRARY)
To solve it, it is just necessary to create the missing file "jni/com_pkgpub_Dev.c". This file content should be manually made based on the automatic generated code contained in the file "jni/com_pkgpub_Dev.h".
Now, it works!
Related
I download the source code of OpenJDK14 and put them in \home\yuanfang\jdk14 and after running bash configure --disable-warnings-as-errors and make images, I build OpenJDK14 successfully, The newly built JDK is in home\yuanfang\jdk14\build\linux-x86_64-server-release\jdk. By the way, I am using Ubuntu 20.04 LTS.
Then I want to debug OpenJDK14 using CLion IDE. I was using CLion 2020.2 and I take the following steps:
After open CLion I choose Create New CMake Project from Sources and choose the directory of \home\yuanfang\jdk14, which is the root directory of the jdk project.
I alter the Run/Debug Configurations to make it look like this:
CLion create a CMakeLists.txt automatically but the file doesn't work, so after googling I find find the correct CMakeLists.txt here at https://github.com/ojdkbuild/ojdkbuild/blob/master/src/java-14-openjdk/CMakeLists.txt. I then rewrite the old CMakeLists.txt using the correct one.
I download the whole repository(that is, github.com/ojdkbuild/ojdkbuild), unzip it and put it into \home\yuanfang\jdk14.
It looks like as follow, the ojdkbuild-master is the newly added folder.
I reload the CMake project, but some CMake error occurs(as follow), why can't CLion find those files? javaI googled but can't find any effective solution. Is there anything I can do or refer to? Thanks in advance.
CMake Error at CMakeLists.txt:19 (include):
include could not find load file:
/home/yuanfang/jdk14/../../resources/cmake/ojdkbuild_common.cmake
CMake Error at CMakeLists.txt:21 (include):
include could not find load file:
/home/yuanfang/jdk14/../../resources/cmake/version.cmake
CMake Error at CMakeLists.txt:93 (add_subdirectory):
add_subdirectory given source
"/home/yuanfang/jdk14/../../deps/rhino/scripting_tasks" which is not an
existing directory.
CMake Error at CMakeLists.txt:98 (ojdkbuild_add_subdirectory):
Unknown CMake command "ojdkbuild_add_subdirectory".
-- Configuring incomplete, errors occurred!
See also "/home/yuanfang/jdk14/cmake-build-debug/CMakeFiles/CMakeOutput.log".
Cannot get compiler information:
Compiler exited with error code 1: /usr/bin/cc -xobjective-c -I/home/yuanfang/jdk14/build/linux-x86_64-server-release/hotspot/variant-server/gensrc/adfiles......./loading/LibraryLoader/jar_src -g -fpch-preprocess -v -dD -E
Using built-in specs.
COLLECT_GCC=/usr/bin/cc
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)
COLLECT_GCC_OPTIONS='-I' '/home/yuanfang/jdk14/build/linux-x86_64-server-release/hotspot/variant-server/gensrc/adfiles' '-I' '......'-g' '-fpch-preprocess' '-v' '-dD' '-E' '-D' '___CIDR_DEFINITIONS_END' '-mtune=generic' '-march=x86-64'
cc1obj -E -quiet -v #/tmp/cci3XM6r -imultiarch x86_64-linux-gnu -D ___CIDR_DEFINITIONS_END /tmp/compiler-file5929385022787926768 -mtune=generic -march=x86-64 -fpch-preprocess -g -fworking-directory -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -dD
cc: fatal error: cannot execute 'cc1obj': execvp: No such file or directory
compilation terminated.
[Failed to reload]
step: check out this projecdt :https://github.com/ojdkbuild/ojdkbuild.git
step: put the source code of OpenJDK14 in ojdkbuild/src/
step: copy reousrces directory and CMakelists.txt to OpenJDK14
step: recomile openjdk and import project to CLin
I have searched the entire web throughly for almost two days now and couldn't come up with a solution to my problem. I hope you guys can help me.
This might be a little specific but I am sure sooner or later others will experience the same problems.
I am currently using NetBeans Dev (Build 201803200002) with Java JDK 9.0.4 on a Windows 10, 64-bit system.
I was working through this JNI tutorial:
https://cnd.netbeans.org/docs/jni/beginning-jni-win.html
Almost at the end, below figure 13, you are supposed to build the project HelloWorldNative (in my case it is called JNITestNative).
But I always get the following error message:
cd 'D:\NetBeans\projects\JNITestNative'
C:\Programme\cygwin\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/d/NetBeans/projects/JNITestNative'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/JNITestNative.dll
make[2]: Entering directory '/cygdrive/d/NetBeans/projects/JNITestNative'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/JNITest.o.d"
gcc -mno-cygwin -Wl,--add-stdcall-alias shared -m32 -c -g -I/cygdrive/C/Program\ Files/Java/jdk-9.0.4/include -I/cygdrive/C/Program\ Files/Java/jdk-9.0.4/include/win32 -MMD -MP -MF "build/Debug/Cygwin-Windows/JNITest.o.d" -o build/Debug/Cygwin-Windows/JNITest.o JNITest.c
gcc: error: shared: No such file or directory
gcc: error: unrecognized command line option '-mno-cygwin'; did you mean '-mno-clwb'?
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/Cygwin-Windows/JNITest.o' failed
make[2]: *** [build/Debug/Cygwin-Windows/JNITest.o] Error 1
make[2]: Leaving directory '/cygdrive/d/NetBeans/projects/JNITestNative'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/d/NetBeans/projects/JNITestNative'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
NetBeans seems to be missing a file which I am expecting it to generate in the first place - JNITest.o
I checked the directories ...jdk-9.0.4/include, ...jdk9.0.4/include/win32 and ...Debug/Cygwin-Windows.
All of them exist, but the files JNITest.o.d or JNITest.o do not.
I tried to replace "cygwin" by "clwb" as suggested in the second error message, but the first error still occurs.
According to some sources in the internet I also removed the whole part "-mno-cygwin" from the additional options but the first error still occurs.
According to some other sources in the internet I added my ...cygwin/bin directory to the include directories, but this did not improve anything.
I have absolutely no idea how to solve this or how to search for other potential solutions anymore.
I hope anyone here can help.
The correct answer was stated by Jorn Vernee in his comment.
A '-' was missing before the argument "shared".
Thank you for that.
For anyone else who might be experiencing this problem, let me sum up how I got from here to a successful build.
According to this and this I added three code lines for the definition of data type __int64, so now my JNITest.c looks like this:
#ifdef __CYGWIN__
#define __int64 long long
#endif
#include <jni.h>
#include <stdio.h>
#include "JNITest.h"
JNIEXPORT void JNICALL Java_com_plaettner_jnitest_JNITest_nativePrint
(JNIEnv *env, jobject obj)
{
printf("\nHello World from C\n");
}
Next I added the packages "mingw64-i686-gcc-core: GCC for Win32" and "mingw64-i686-gcc-g++: GCC for Win32" to my Cygwin.
In NetBeans options - C/C++ - Build Tools I then changed the C and C++ Compiler from gcc/g++ to i686-w64-mingw32-gcc/g++ respectively.
In the project properties in the categories Build - C Compiler/C++ Compiler I changed the additional options from "-mno-cygwin -Wl,--add-stdcall-alias -shared -m32" to "-Wl,--add-stdcall-alias -shared" and added my ...cygwin/bin directory to the include directories.
This leads to a successful build already. Anyway I added "-m32" to the additional options again and changed c/c++ Compiler back to gcc/g++ to keep compliance to the tutorial.
Now this leads to a successful build as well, although it didn't before.
Removing the ...cygwin/bin directory from the include directories leads to a failed build again and the whole process has to be repeated.
At least for me it worked this way.
How can I ask UMLGraph to generate a single diagram for all the underlying .java classes within a package ?
I am using UMLGraph along with Graphviz to generate a .png UML diagram file.
The command that I am running to geenrate a.dot file is :
java -jar C:/Program Files/Java/jdk1.7.0_80/lib/UmlGraph.jar -all -private A.java
This runs succesfully to geenrate a .dot file.
However,I wish to create a single UML diagram out of them ( They are all linked to eachother via java code).
The "uml-parser-test-1" (folder/package) contains all about 5 .java files and for that I am running
C:/Users/xyz > java -jar "C:/Program Files/Java/jdk1.8.0_60/lib/UmlGraph.jar" -all -private "D:/xyz/abcd/uml-parser-test-1/"
When I run above code , I get an error : UMLGRAPH ERROR - ILLEGAL PACKAGE NAME
Where am I going wrong
**EDIT:: 6th Oct**
There was an issue with umlgraph.jar path and I had corrected it. Thanks for pointing that out.
Now I am able to run the command you suggested without any errors. THe thing is my "Persons" package(folder) contains 4 java files(A,B,C,D.java). When I run the command, it generated .dot file on the command line and not in my file system.Moreover, it is incomplete as there is no information about classes :
Below is the trace of my command line .
C:\Users\xyz>java -classpath "C:/Program Files/Java/jdk1.8.0_60/lib/UmlGraph.jar;C:/Program Files/Java/jdk1.8.0_20/lib/tools.jar" org.umlgraph.doclet.UmlGraph -package -output - -sourcepath "C:/Program Files/Java/jdk1.8.0_60/lib/Persons" org.umlgraph.doclet
Loading source files for package org.umlgraph.doclet...
UmlGraph: warning - No source files for package org.umlgraph.doclet
Constructing Javadoc information...
UmlGraph: warning - No source files for package org.umlgraph.doclet
UMLGraph doclet version R5_7_2-3-gee82a7 started
Building general class diagram
#!/usr/local/bin/dot
#
# Class diagram
# Generated by UMLGraph version R5_7_2-3-gee82a7 (http://www.umlgraph.org/)
#
digraph G {
edge [fontname="arial",fontsize=10,labelfontname="arial",labelfontsize=10];
node [fontname="arial",fontsize=10,shape=plaintext];
nodesep=0.25;
ranksep=0.5;
}
2 warnings
Any idea, why it is not parsing the class details?
You must specify in the command line invocation the package name and the directory where its source code is located. The following example, when run in the UMLGraph directory, generates a diagram for the UMLGraph classes.
java -classpath "lib/UmlGraph.jar;C:\Program Files\Java\jdk1.8.0_20/lib/tools.jar" org.umlgraph.doclet.UmlGraph -package -output - -sourcepath src/main/java org.umlgraph.doclet | dot -Tpng -oumlgraph.png
I am trying to use JNI to call a Java program from a C++ program. A supplier has put in place some phone apparatus and it only uses C++. I want to write a Screen Popper but don't want to do it in C++ so therefore want to pass across the event of the phone call coming in and the number to a Java routine to handle. I am using Netbeans as it makes the coding easier (usually!). I have not done C++ before which is why I want to escape to Java ASAP!
I am following instructions here: http://www.ibm.com/developerworks/java/tutorials/j-jni/j-jni.html
Which seem to set out how to call a Java routine from C++ but I cannot get it to compile. I have got as far as I with lots of help from this site but now I'm stumped.
I have added the '-D__int64=long long' switch to the compiler options for the project and added the Java libraries to the Application include paths. I have reparsed the code using code assistance. But now I'm left with this error:
make[1]: Entering directory '/cygdrive/f/Javadev/Sample2'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/sample2.exe
make[2]: Entering directory '/cygdrive/f/Javadev/Sample2'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f build/Debug/Cygwin_4.x-Windows/main.o.d
g++.exe -D__int64=long long -c -g -I/cygdrive/C/Program\ Files\ \(x86\)/Java/jdk1.6.0_33/include/win32 -I/cygdrive/C/Program\ Files\ \(x86\)/Java/jdk1.6.0_33/include -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
nbproject/Makefile-Debug.mk:65: recipe for target 'build/Debug/Cygwin_4.x-Windows/main.o' failed
make[2]: Leaving directory '/cygdrive/f/Javadev/Sample2'
nbproject/Makefile-Debug.mk:58: recipe for target '.build-conf' failed
make[1]: Leaving directory '/cygdrive/f/Javadev/Sample2'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
g++: error: long: No such file or directory
make[2]: *** [build/Debug/Cygwin_4.x-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
All source files are under F:\javadev, Sample2 is C++ and Sample3 is Java. Is there something else I need to include from Cygwin? It seems to say there is a problem with 'long' but that only really occurs in the switch and without it it fails even more catastrophically, saying that __int64 does not have a type.
While trying to build a library that uses javah, I ran into a classpath issue. Apparently, the classpath is prefixed with the JDK path: please notice the final search path is wrong. How should I do instead?
elmarco#makai:~/src/sasl/java/CyrusSasl (mingw32 *%)$ CLASSPATH=$PWD javah -o javasasl.h -jni -verbose Sasl
error: cannot access Sasl
class file for Sasl not found
javadoc: error - Class Sasl not found.
[ Search Path: /usr/java/jdk1.6.0_24/jre/lib/resources.jar:/usr/java/jdk1.6.0_24/jre/lib/rt.jar:/usr/java/jdk1.6.0_24/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0_24/jre/lib/jsse.jar:/usr/java/jdk1.6.0_24/jre/lib/jce.jar:/usr/java/jdk1.6.0_24/jre/lib/charsets.jar:/usr/java/jdk1.6.0_24/jre/lib/modules/jdk.boot.jar:/usr/java/jdk1.6.0_24/jre/classes//home/elmarco/src/sasl/java/CyrusSasl ]
elmarco#makai:~/src/sasl/java/CyrusSasl (mingw32 *%)$ ls Sasl.java
Sasl.java
Thanks for your help!
(this is jdk1.6.0_24 on Fedora 14)
I usually avoid the CLASSPATH environment variable. This should work (and maybe without a problem):
javah -classpath .;<your-path> -o javasasl.h -jni -verbose Sasl
If don't need nothing but the local path, then you don't have to specify a -classpath option, . is the default value.
Note - you have to compile Sasl.java first. javah expects a class file. (Getting started)
I think it's simply a bug in how the javah outputs its actual classpath. What happens is that it has a bunch of places where it searches for built-in classes, and apart from them, it also uses the stuff in $CLASSPATH. When it prints the actual classpath used, they do something like this (pseudo code, assuming implicitEntries is a list of builtin classpath entries, and explicitEntries is a list of the the directories specified in $CLASSPATH):
print implicitEntries.join(pathSeparator) + explicitEntries.join(pathSeparator)
where it should have been
print implicitEntries.join(pathSeparator) + pathSeparator + explicitEntries.join(pathSeparator)
The following works fine for me:
$ ls
Sasl.class Sasl.java
$ javah -classpath . -o javasasl.h -jni -verbose Sasl [ Search Path: /usr/java/jdk1.6.0/jre/lib/resources.jar:/usr/java/jdk1.6.0/jre/lib/rt.jar:/usr/java/jdk1.6.0/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0/jre/lib/jsse.jar:/usr/java/jdk1.6.0/jre/lib/jce.jar:/usr/java/jdk1.6.0/jre/lib/charsets.jar:/usr/java/jdk1.6.0/jre/classes/. ]
[Creating file javasasl.h]
[search path for source files: [.]]
[search path for class files: [/usr/java/jdk1.6.0/jre/lib/resources.jar, /usr/java/jdk1.6.0/jre/lib/rt.jar, /usr/java/jdk1.6.0/jre/lib/sunrsasign.jar, /usr/java/jdk1.6.0/jre/lib/jsse.jar, /usr/java/jdk1.6.0/jre/lib/jce.jar, /usr/java/jdk1.6.0/jre/lib/charsets.jar, /usr/java/jdk1.6.0/jre/classes, /usr/java/jdk1.6.0/jre/lib/ext/dnsns.jar, /usr/java/jdk1.6.0/jre/lib/ext/localedata.jar, /usr/java/jdk1.6.0/jre/lib/ext/sunpkcs11.jar, /usr/java/jdk1.6.0/jre/lib/ext/sunjce_provider.jar, .]]
[loading ./Sasl.class]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Throwable.class)]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Class.class)]
[done in 585 ms]
$ ls
javasasl.h Sasl.class Sasl.java
Now, since the header file generation doesn't seem to work for you... are you sure you have Sasl.class in the current directory? javah works with byte code files, not Java source files.
You show here, that the source file is available ...
(mingw32 *%)$ ls Sasl.java
Sasl.java
but missing is the class file (Sasl.class).
error: cannot access Sasl
class file for Sasl not found
Compile it first.