Why is CLASSPATH prefixed with JDK path? - java

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.

Related

How to compile xslt2-transformer.oxt LibreOffice extension

I am trying to compile the xslt2-transformer extension, because I can’t find the LibreOffice extension xslt2-transformer.oxt on the web site (if anybody has it, he is welcome).
To build from source code, I proceeded like that:
$ git clone https://github.com/dtardon/xslt2-transformer.git
$ cd xslt2-transformer/
$ make
I am getting a lot of (similar) errors during build:
mkdir -p build/classes && \
javac -d build/classes -source 1.5 -target 1.5 \
-cp "external/saxon9.jar:" com/sun/star/comp/xsltfilter/Base64.java \
com/sun/star/comp/xsltfilter/XSLTFilterOLEExtracter.java \
com/sun/star/comp/xsltfilter/XSLTransformer.java && \
touch build/javac.done
com/sun/star/comp/xsltfilter/XSLTFilterOLEExtracter.java:27: error: package com.sun.star.bridge does not exist
import com.sun.star.bridge.XBridgeFactory;
^
com/sun/star/comp/xsltfilter/XSLTFilterOLEExtracter.java:28: error: package com.sun.star.bridge does not exist
import com.sun.star.bridge.XBridge;
^
[...]
symbol: class XConnector
location: class XSLTFilterOLEExtracter
com/sun/star/comp/xsltfilter/XSLTFilterOLEExtracter.java:321: error: cannot find symbol
XConnector xConnector = UnoRuntime.queryInterface(XConnector.class, x);
^
symbol: class XConnector
location: class XSLTFilterOLEExtracter
100 errors
1 warning
make: *** [build/javac.done] Error 1
I think my CLASSPATH is not up-to-date. I need to add the com.sun.star package and classes.
Since I am (currently) on OSX, my LibreOffice is installed on /Applications/LibreOffice.app and I found some classes in ./Contents/Resources/java.
So I update the CLASSPATH that way:
export CLASSPATH=/Applications/LibreOffice.app/Contents/Resources/java:$CLASSPATH
But, I have the same errors. How can I fix that?
EDIT 1 put some jar in the CLASSPATH
I tried that:
$ export CLASSPATH=/Applications/LibreOffice.app/Contents//Resources/java/ridl.jar:.
I have less errors.
EDIT 2 The build succeed!
I finally added the following jar files to the CLASSPATH:
/Applications/LibreOffice.app/Contents//Resources/java/ridl.jar
/Applications/LibreOffice.app/Contents//Resources/java/jurt.jar
/Applications/LibreOffice.app/Contents//Resources/java/juh.jar
/Applications/LibreOffice.app/Contents//Resources/java/unoil.jar
And I get the extension!
Finally, to build from source code, I proceeded like that:
git clone https://github.com/dtardon/xslt2-transformer.git
cd xslt2-transformer/
export CLASSPATH=/Applications/LibreOffice.app/Contents/Resources/java/ridl.jar:\
/Applications/LibreOffice.app/Contents/Resources/java/jurt.jar:\
/Applications/LibreOffice.app/Contents/Resources/java/juh.jar:\
/Applications/LibreOffice.app/Contents/Resources/java/unoil.jar
make
The result is build/xslt2-transformer.oxt.

Using UMLGraph to generate single dot file for multiple java classes

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

GnuPG for Java library ant build issue/bug

I'm working GnuPG Java API to encrypt/decrypt files.
Googled and found a Java Wrapper GnuPG for Java, Java wrapper for GPGME(GnuPG Made Easy,C language library).
Official website also referring this as the Java wrapper.
So followed the instructions, set up ant and tried to run ant clean release
it is throwing errors.
But maven build working and jar file also generated.
Following error occured while running ant.
C:\Users\user\Desktop\MFT\gnupg-for-java-master>ant clean release
Buildfile: C:\Users\user\Desktop\MFT\gnupg-for-java-master\build.xml
clean-native:
[exec] rm -f GnuPGContext.o GnuPGData.o GnuPGGenkeyResult.o GnuPGKey.o GnuPGSignature.o gpgmeutils.o *~
[exec] rm -f C:\Users\user\Desktop\MFT\gnupg-for-java-master\build/gnupg-for-java.dll
[exec] rm -f com_freiheit_gnupg_GnuPGContext.h com_freiheit_gnupg_GnuPGData.h com_freiheit_gnupg_GnuPGGenkeyResult.h com_freiheit_gnupg_GnuPG
Key.h com_freiheit_gnupg_GnuPGSignature.h
clean:
[delete] Deleting directory C:\Users\user\Desktop\MFT\gnupg-for-java-master\build\classes
prepare:
compile-java:
[mkdir] Created dir: C:\Users\user\Desktop\MFT\gnupg-for-java-master\build\classes
[javac] C:\Users\user\Desktop\MFT\gnupg-for-java-master\build.xml:21: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=l
ast; set to false for repeatable builds
[javac] Compiling 8 source files to C:\Users\user\Desktop\MFT\gnupg-for-java-master\build\classes
gen-jni-headers:
prepare:
compile-java:
[javac] C:\Users\user\Desktop\MFT\gnupg-for-java-master\build.xml:21: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=l
ast; set to false for repeatable builds
generate-jni-headers:
[exec] C:\Program Files (x86)/Java/jdk1.7.0_51/bin/javah -classpath C:\Users\user\Desktop\MFT\gnupg-for-java-master\build\classes -jni com.freih
eit.gnupg.GnuPGContext com.freiheit.gnupg.GnuPGData com.freiheit.gnupg.GnuPGGenkeyResult com.freiheit.gnupg.GnuPGKey com.freiheit.gnupg.GnuPGSigna
ture
[exec] /bin/sh: -c: line 0: syntax error near unexpected token `('
[exec] /bin/sh: -c: line 0: `C:\Program Files (x86)/Java/jdk1.7.0_51/bin/javah -classpath C:\Users\user\Desktop\MFT\gnupg-for-java-master\build\c
lasses -jni com.freiheit.gnupg.GnuPGContext com.freiheit.gnupg.GnuPGData com.freiheit.gnupg.GnuPGGenkeyResult com.freiheit.gnupg.GnuPGKey com.fre
iheit.gnupg.GnuPGSignature'
[exec] make: *** [com_freiheit_gnupg_GnuPGContext.h] Error 2
BUILD FAILED
C:\Users\user\Desktop\MFT\gnupg-for-java-master\build.xml:71: The following error occurred while executing this line:
C:\Users\user\Desktop\MFT\gnupg-for-java-master\build.xml:63: exec returned: 2
Total time: 4 seconds
Update
I changed the Java home in GNUmakefile, Now it is throwing different error. Seems c library not found and this API is written for Unix system seems by reading the error message. What C library missing ?
generate-jni-headers:
[exec] C:\Java\jdk1.7.0_75/bin/javah -classpath C:\Users\user\Desktop\MFT\gnupg-for-java-master\build\classes -jni com.freiheit.gnupg.GnuPGConte
xt com.freiheit.gnupg.GnuPGData com.freiheit.gnupg.GnuPGGenkeyResult com.freiheit.gnupg.GnuPGKey com.freiheit.gnupg.GnuPGSignature
gen-jni-library:
recompile-c-code:
[exec] mingw32-gcc -g -Werror -Wall -Wno-deprecated-declarations -fPIC -mms-bitfields -Wl,--add-stdcall-alias -D_REENTRANT -D_THREAD_SAFE -D_FIL
E_OFFSET_BITS=64 -DLARGEFILE_SOURCE=1 -I"C:\Java\jdk1.7.0_75/include" -I"C:\Java\jdk1.7.0_75/include/win32" -I"C:\Program Files (x86)/GNU/GnuPG/includ
e" -c GnuPGContext.c
[exec] /bin/sh: mingw32-gcc: command not found
[exec] make: *** [GnuPGContext.o] Error 127
BUILD FAILED
C:\Users\user\Desktop\MFT\gnupg-for-java-master\build.xml:82: The following error occurred while executing this line:
C:\Users\user\Desktop\MFT\gnupg-for-java-master\build.xml:75: exec returned: 2
Total time: 7 seconds
Can anyone help me to solve this issue ?
Where I'm making mistake ?
I rewrote my answer because I wanted to create a complete guide.
Install GnuPG and MinGW-Get to a directory without spaces.
After you installed MinGW with !!!GUI!!!, open mingw-get, install these components:
mingw32-gcc (check all)
mingw32-libz (the dll is the most important)
Download and install MSYS, that is a command line toolkit for running commands like make.
Then put c:\msys\1.0\bin\ (or wherever you installed it) on the beginning of the PATH variable. Restart eclipse or open a new cmd, and it should work.
In the build.xml:
line 21:
classpath="lib/junit-4.4.jar" added.(and the junit is in the lib dir)
In the GNUmakefile:
line 9 :
ALL_CFLAGS := -Wall -Wno-deprecated-declarations -fPIC
line 10:
ALL_CPPFLAGS = -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -DLARGEFILE_SOURCE=1 \
-I"c:/WORK/x/gnu/jdk/jdk1.8.0_25/include" -I"c:/WORK/x/gnu/jdk/jdk1.8.0_25/include/win32"
line 21-27:
JAVA_HOME := c:/WORK/x/gnu/jdk/jdk1.8.0_25
ALL_CFLAGS += -mms-bitfields -Wl,--add-stdcall-alias
ALL_CPPFLAGS += -I"c:/WORK/x/gnu/jdk/jdk1.8.0_25/include/win32" -I"c:/WORK/x/gnu/jdk/jdk1.8.0_25/include" -I"c:/GNU/GnuPG/include"
ALL_LDFLAGS := -s -shared -Wl,--enable-auto-import
ALL_LIBS := -L"c:/GNU/GnuPG" -lgpgme-11
GNUPG_LIB := $(BUILD_DIR)/gnupg-for-java.dll
line 63:
$(CC) $(DEBUG) $(ALL_CFLAGS) $(ALL_LDFLAGS) $^ -o "$(BUILD_DIR)/gnupg-for-java.dll" $(ALL_LIBS)
Summary: This is working for me and outputs the jar and dll file to the build directory. My work directory was c:/WORK/x so replace the paths where it is different. Don't use "Program Files" anywhere, as you can see I had to copy everything from there.
The error message is telling that it cannot find mingw32-gcc in /bin/sh.
You should install mingw at first and add it to your path. Check that mingw32-gcc can be launched from the command line.
Are you running the ant script from cygwin? It's a bit strange that it is referring /bin/sh. Maybe you should try to run it from cygwin. Or check the build.xml file to see how mingw32-gcc is called. It must be recompile-c-code target.

Android NDK: Eclipse parameter and javah

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!

Why can't I load this class file in Rhino console?

I'm prototyping a web page scraper using Rhino and Env-js. Nevermind that the documentation for both projects is atrocious... I'm trying to load up the File.java example class that is supplied with Rhino. For simplicity sake, I've got File.java, js.jar, jline.jar and env.rhino.1.2.js all in one directory. I've tried specifying the current directory using the classpath command line option, but still whenever I call defineClass("File") I get an error saying the class file isn't found. What am I doing wrong here??
$ ls -1
File.java
env.rhino.1.2.js
jline.jar
js.jar
$ java -cp .:js.jar:jline.jar jline.ConsoleRunner org.mozilla.javascript.tools.shell.Main -opt -1
Rhino 1.7 release 2 2009 03 22
js> defineClass("File")
js: "<stdin>", line 2: Class "File" not found.
at <stdin>:2
Don't you need to compile File.java before using it, as the classpath "." only makes sense if it contains some compiled class in it?

Categories

Resources