Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 220
Mr.Chowdary Avatar asked May 18 '15 09:05

Mr.Chowdary


2 Answers

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.

like image 65
gaRos Avatar answered Sep 27 '22 20:09

gaRos


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.

like image 25
Oleg Pavliv Avatar answered Sep 27 '22 18:09

Oleg Pavliv