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 9 of 9

Thread: Help required in creating header file using java

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help required in creating header file using java

    Hi All,
    May i know how to create c header file using java jni for a class which is inside a jar file.
    I have created a jar called HelloWorld.jar (using Netbeans) which has only class file as below

    package example;

    public class HelloWorld {
    public native void print(); //native method
    static //static initializer code
    {
    System.loadLibrary("CLibHelloWorld");
    }

    public static void main(String[] args)
    {
    HelloWorld hw = new HelloWorld();
    hw.print();
    }
    }
    i tried following command
    javah -jni HelloWorld
    i am getting below error
    error: cannot access HelloWorld
    class file for HelloWorld not found
    javah -jni example.HelloWorld
    i am getting below error
    error: cannot access HelloWorld
    class file for HelloWorld not found

    Please let me know how to create the c header file.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,350
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: Help required in creating header file using java

    for a class which is inside a jar file.
    What have you tried with classpath?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help required in creating header file using java

    Quote Originally Posted by Norm View Post
    What have you tried with classpath?
    No i havent tried... May i know how to do that?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,350
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: Help required in creating header file using java

    how to do that?
    Read the doc for the javah command.

    Why put the class in a jar file? Try working with the class outside of the jar file.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help required in creating header file using java

    Quote Originally Posted by Norm View Post
    Read the doc for the javah command.

    Why put the class in a jar file? Try working with the class outside of the jar file.
    I just given an example, actual scenario is different. Jar will do other functionality too...

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,350
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: Help required in creating header file using java

    What happens when the class file is not in a jar file?

    I just given an example, actual scenario is different.
    The answer could depend on the actual scenario.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help required in creating header file using java

    Quote Originally Posted by Norm View Post
    What happens when the class file is not in a jar file?


    The answer could depend on the actual scenario.
    The jar has other functionality of large project which i cant mention here sorry. but i cant grantee this HelloWorld class is not dependent on other class and its functionality already clearly mentioned in my first post.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,350
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: Help required in creating header file using java

    Try it different ways to see what happens.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2013
    Location
    Kolkata,India
    Posts
    4
    My Mood
    Relaxed
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Help required in creating header file using java

    Step 1:

    Say I have a folder in my desktop named as "example".
    Inside it,I copy paste your code.

    ScreenShot1.jpg

    Step 2:
    Compile the Java Code.

    2.jpg

    Step 3:
    Generate header file from java class
    Note: You need to run javah from the directory containing example/HelloWorld.class

    3.png


    You will find a "example_HelloWorld.h" being created/generated at the Desktop.

    Untitled.jpg


    Cheers
    Sandeep

Similar Threads

  1. Java Developer required!
    By Rilwood in forum Paid Java Projects
    Replies: 0
    Last Post: December 3rd, 2012, 11:36 AM
  2. Replies: 1
    Last Post: June 26th, 2012, 01:04 AM
  3. Creating sms sending appication.... Help required..
    By psomaiya17 in forum Member Introductions
    Replies: 0
    Last Post: July 22nd, 2011, 12:11 PM
  4. New to Java....still learning...Help Required
    By muraduk in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 12th, 2010, 04:15 PM

Tags for this Thread