Unix Machine for calling Native Method of C


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Unix Machine for calling Native Method of C
# 1  
Old 11-08-2006
Unix Machine for calling Native Method of C

hi all
i have a unix machine (FBD). I have Also installed java of Version (j2sdk1.4.1_07) on unix machine. Now i

want to Call C Native function in Java Which is declared as Native. i am doing this by following steps:
1) Making Echo.java File Which is having The following lines of code.
class Echo {
public native void runEcho();

static {
System.loadLibrary("echo");
}

public static void main(String[] args) {
new Echo().runEcho();
}
}
2) Compiling the Code:
$ javac Echo,java
$ javah Echo ----- which will make the header file used in c programe
3) writing the EchoImp.c File Which contains the following line of code
#include "jni.h"
#include "Echo.h"//the java class above compiled with javah
#include <stdio.h>

JNIEXPORT void JNICALL
Java_Echo_runEcho(JNIEnv *env, jobject obj)
{
char buf[64];
gets(buf);
printf(buf);
}
4) Making the Library echo
$ cc -G -I/usr/local/java/include -I/usr/local/java/include/linux
Echo.c -o libecho.so
5) Now Setting The Libarary Path
$ setenv LD_LIBRARY_PATH <Path>
6) Now Finally Excute the Java Program to call c function
$ java Echo


but while executing i m getting Error Like :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no echo in java.libra
ry.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
at Echo.<clinit>(Echo.java:5)

i have also set the path but no results ....
plz help me out

Kamal Kant
email removed
sb

Last edited by vino; 11-08-2006 at 03:33 AM..
# 2  
Old 11-08-2006
Executing Java code for calling Native Method of C Unix Machine

Executing Java code for calling Native Method of C Unix Machine



hi all
i have a unix machine (FBD). I have Also installed java of Version (j2sdk1.4.1_07) on unix machine. Now i

want to Call C Native function in Java Which is declared as Native. i am doing this by following steps:
1) Making Echo.java File Which is having The following lines of code.
class Echo {
public native void runEcho();

static {
System.loadLibrary("echo");
}

public static void main(String[] args) {
new Echo().runEcho();
}
}
2) Compiling the Code:
$ javac Echo,java
$ javah Echo ----- which will make the header file used in c programe
3) writing the EchoImp.c File Which contains the following line of code
#include "jni.h"
#include "Echo.h"//the java class above compiled with javah
#include <stdio.h>

JNIEXPORT void JNICALL
Java_Echo_runEcho(JNIEnv *env, jobject obj)
{
char buf[64];
gets(buf);
printf(buf);
}
4) Making the Library echo
$ cc -G -I/usr/local/java/include -I/usr/local/java/include/linux
Echo.c -o libecho.so
5) Now Setting The Libarary Path
$ setenv LD_LIBRARY_PATH <Path>
6) Now Finally Excute the Java Program to call c function
$ java Echo


but while executing i m getting Error Like :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no echo in java.libra
ry.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
at Echo.<clinit>(Echo.java:5)

i have also set the path but no results ....
plz help me out

Kamal Kant
email removed
sb

Last edited by vino; 11-08-2006 at 03:33 AM..
# 3  
Old 11-08-2006
Executing Java code for calling Native Method of C On Unix Machine

Executing Java code for calling Native Method of C On Unix Machine
hi all
i have a unix machine (FBD). I have Also installed java of Version (j2sdk1.4.1_07) on unix machine. Now i

want to Call C Native function in Java Which is declared as Native. i am doing this by following steps:
1) Making Echo.java File Which is having The following lines of code.
class Echo {
public native void runEcho();

static {
System.loadLibrary("echo");
}

public static void main(String[] args) {
new Echo().runEcho();
}
}
2) Compiling the Code:
$ javac Echo,java
$ javah Echo ----- which will make the header file used in c programe
3) writing the EchoImp.c File Which contains the following line of code
#include "jni.h"
#include "Echo.h"//the java class above compiled with javah
#include <stdio.h>

JNIEXPORT void JNICALL
Java_Echo_runEcho(JNIEnv *env, jobject obj)
{
char buf[64];
gets(buf);
printf(buf);
}
4) Making the Library echo
$ cc -G -I/usr/local/java/include -I/usr/local/java/include/linux
Echo.c -o libecho.so
5) Now Setting The Libarary Path
$ setenv LD_LIBRARY_PATH <Path>
6) Now Finally Excute the Java Program to call c function
$ java Echo


but while executing i m getting Error Like :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no echo in java.libra
ry.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
at Echo.<clinit>(Echo.java:5)

i have also set the path but no results ....
plz help me out

Kamal Kant
email removed
sb

Last edited by vino; 11-08-2006 at 03:33 AM..
# 4  
Old 11-08-2006
sbeyonduf007, you are flooding the forum with your posts. Please do not do that. I have merged all the threads.

As for the actual problem, I think LD_LIBRARY_PATH should be available on FreeBSD.

Code:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/dir/containing/echo.so

# 5  
Old 11-08-2006
Executing Java code for calling Native Method of C On Unix Machine

Executing Java code for calling Native Method of C On Unix Machine
hi all
i have a unix machine (FBD). I have Also installed java of Version (j2sdk1.4.1_07) on unix machine. Now i

want to Call C Native function in Java Which is declared as Native. i am doing this by following steps:
1) Making Echo.java File Which is having The following lines of code.
class Echo {
public native void runEcho();

static {
System.loadLibrary("echo");
}

public static void main(String[] args) {
new Echo().runEcho();
}
}
2) Compiling the Code:
$ javac Echo,java
$ javah Echo ----- which will make the header file used in c programe
3) writing the EchoImp.c File Which contains the following line of code
#include "jni.h"
#include "Echo.h"//the java class above compiled with javah
#include <stdio.h>

JNIEXPORT void JNICALL
Java_Echo_runEcho(JNIEnv *env, jobject obj)
{
char buf[64];
gets(buf);
printf(buf);
}
4) Making the Library echo
$ cc -G -I/usr/local/java/include -I/usr/local/java/include/linux
Echo.c -o libecho.so
5) Now Setting The Libarary Path
$ setenv LD_LIBRARY_PATH <Path>
6) Now Finally Excute the Java Program to call c function
$ java Echo


but while executing i m getting Error Like :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no echo in java.libra
ry.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
at Echo.<clinit>(Echo.java:5)

i have also set the path but no results ....
plz help me out

Kamal Kant
sb

Last edited by blowtorch; 11-08-2006 at 03:57 AM.. Reason: remove email address
# 6  
Old 11-08-2006
sbeyonduf007, I have just merged another of your posts into this thread. Also, do *not* post your email address with your posts. It is against the rules and your post will be edited to remove the email address.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Wanna learn native GUI programming in UNIX - Linux ?

Hi , wanna learn native GUI programming in Unix-Linux instead of Gtk and Qt. No problem. You don't need a cross platform Gui toolkit like Gtk and Qt. And the code and syntax is also not more or less than others. Check out this code for a simple mainwindow for your application that is openend in... (0 Replies)
Discussion started by: Sennenmut
0 Replies

2. Cybersecurity

Looking for suggestion on authentication method for UNIX/Windows

Hello, We have mid level infrastructure of all on-premises servers. All windows servers are getting authenticated by Microsoft Active Directory Services, half Unix (Solaris+Linux) servers are getting authentication by NIS and other half by LDAP. We have plans to migrate from NIS to LDAP, so... (2 Replies)
Discussion started by: solaris_1977
2 Replies

3. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

Hello Experts, I have the following questions to be discussed here at this esteemed discussion forum. I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies

4. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

5. UNIX for Advanced & Expert Users

best method to compare 2 big files in unix

Hi , I have a requirement to compare 2 files which can contain 40 million or more records and more than 20 fields to compare . Currently I am using awk scripting , and since awk has a memory issue, I am not able to process file more than 10 million records. Any suggestions or pointers to... (7 Replies)
Discussion started by: rashmisb
7 Replies

6. Shell Programming and Scripting

Calling Java Method from UNIX using shell script

Hi All, I need to call a java method from a shell script. I know we can use the command java ClassName to call the main method in it. But I need to call another method that is there in the class and pass an email to it. Can I use java ClassName.MethodName(email) Any help will be... (4 Replies)
Discussion started by: RahulK
4 Replies

7. Shell Programming and Scripting

calling a method inside awk

Hi All, How do we call a method existing in another file inside awk. After matching a pattern i want to call a method secureCopy that exists in another file, but method not getting called: ls -l | awk -v var2=$servername -v var1=$srcserverpath -v var3=$tgtpath '... (1 Reply)
Discussion started by: abhinav192
1 Replies

8. Programming

Regarding Native method

Hi, I am working with solaris 9 and I am using jre1.6. In my application,I am using java and C++ in my application.Basically we are using the java for front end and C/C++ for back hand.So I have to call the C/C++ source code form java code.we are using native methods for it.. So application... (1 Reply)
Discussion started by: smartgupta
1 Replies

9. Programming

Issue related to native method

Hi, I am working with java and C/C++.In my java code I am using the native method to work with C/C++.So I am getting some error in C/C++ source code which I am not able to find it because It is throwing the only java null Exception.... Is there any way by which I can see the error in java console... (0 Replies)
Discussion started by: smartgupta
0 Replies

10. UNIX for Dummies Questions & Answers

calling script in target machine

I know that schedulers handle callign scripts on different machines. If I want to call a script that's on the target machine and know whether the script ran fine or not, can it be done in shell script? what kind of commands would that have? Thank you (1 Reply)
Discussion started by: bryan
1 Replies
Login or Register to Ask a Question

Featured Tech Videos