Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to compile a java program that uses a loaded library inside another compiled class file?

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to compile a java program that uses a loaded library inside another compiled class file?

    Hello,

    I've been able to compile a java file that loads a library from a DLL file written in C++.
    Yet I still can't compile another java file which makes use of that compiled java class file.
    Error Message: cannot find symbol: HelloNative.greeting();
    My point is to be able to use that loaded library manually and completely.
    Can anyone point out how?

    Thanks in advance.
    java_aim.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,453
    My Mood
    Mellow
    Thanks
    146
    Thanked 607 Times in 594 Posts

    Default Re: How to compile a java program that uses a loaded library inside another compiled class file?

    Can you post a simple, short example that demonstrates what you're trying to do? Through imports or by proximity (on the CLASSPATH or in the same project/folder), what you propose should be very simple, so it's difficult to say why you're having problems without an example.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to compile a java program that uses a loaded library inside another compiled class file?

    Quote Originally Posted by GregBrannon View Post
    Can you post a simple, short example that demonstrates what you're trying to do? Through imports or by proximity (on the CLASSPATH or in the same project/folder), what you propose should be very simple, so it's difficult to say why you're having problems without an example.
    //HelloNative.c

    #include "HelloNative.h"
    #include <stdio.h>
    #include <iostream>

    using std::cout;
    using std::endl;

    int c = 0;

    JNIEXPORT void JNICALL Java_HelloNative_greeting(JNIEnv * env, jclass cl)
    {
    printf("Hello Java and C function calling!\n");
    cout << c << ": This is about calling a C++ native function..." << endl;
    cout << c << ": Just another line..." << endl;
    cout << c++ << ": This is C++." << endl;
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////
    //HelloNative.h

    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class HelloNative */

    #ifndef _Included_HelloNative
    #define _Included_HelloNative
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
    * Class: HelloNative
    * Method: greeting
    * Signature: ()V
    */
    JNIEXPORT void JNICALL Java_HelloNative_greeting
    (JNIEnv *, jclass);

    #ifdef __cplusplus
    }
    #endif
    #endif

    ////////////////////////////////////////////////////////////////
    //HelloNative.java

    public class HelloNative {

    /**
    * @param args
    */
    public static native void greeting();

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

    ////////////////////////////////////////////////////////////
    //HelloNativeTest.java

    import javax.swing.JOptionPane;

    public class HelloNativeTest {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    for(int i = 0;i<10; ++i){

    HelloNative.greeting();
    }
    //JOptionPane.showMessageDialog(null,"Are you OK?");
    }

    }

    //DONE

Similar Threads

  1. How do I use a class inside a library?
    By Noobie1569 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 14th, 2013, 07:00 PM
  2. HOW TO EDIT THE LIBRARY .CLASS FILE IN THE JAVA
    By kranthi24 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 21st, 2013, 06:46 AM
  3. HOW TO EDIT THE LIBRARY .CLASS FILE IN THE JAVA
    By kranthi24 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 21st, 2013, 06:46 AM
  4. Urgent! How to compile a whole library to Jar
    By JavaCup in forum Java Theory & Questions
    Replies: 2
    Last Post: May 11th, 2012, 11:46 AM