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

Thread: Need help upgrading an old Makefile for generating Native class headers

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Location
    Midwest US
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question Need help upgrading an old Makefile for generating Native class headers

    I'm trying to compile the JCurses package (https://github.com/kba/jcurses), but its Makefile (created by ./configure) still uses the obsolete javah mechanism for generating C headers for its Native classes. I have two problems:

    1) I'm new to Java and I don't understand how the new mechanism works
    2) I don't know how to modify either ./configure or the Makefile it generates to use the new mechanism

    (Ideally, a precompiled binary would be the best solution, but the only one available (which may still not work anymore) is for Windows.

    My environment:
    Operating System: Linux
    Distribution: openSUSE Leap 15.3 x86_64
    java version "17" 2021-09-14 LTS
    Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
    Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

  2. #2
    Junior Member
    Join Date
    Jun 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help upgrading an old Makefile for generating Native class headers

    To upgrade the Makefile for generating Native class headers in the JCurses package using the modern approach, you'll need to replace the old javah mechanism with the javac -h option, which is the recommended way as of JDK 8 and later. Here's a step-by-step guide on how to do this:

    Step 1: Understand the Changes
    In modern Java development, the javac compiler provides the -h option to generate header files for native methods. This eliminates the need for the old javah tool.

    Step 2: Modify the Makefile
    Since you mentioned the Makefile is generated by ./configure, you'll need to edit either the generated Makefile or the configuration script to ensure the new mechanism is used.

    Option A: Modify the Generated Makefile
    Look for the section in the generated Makefile responsible for compiling native methods. It may have lines similar to invoking javah. You'll replace these lines with javac -h.

    Here's a basic example of what you might change:

    make
    Copy code
    # Old javah command
    # javah -jni -d $(OUTPUTDIR) -classpath $(CLASSPATH) com.example.NativeClass

    # Replace with javac -h
    javac -h $(OUTPUTDIR) -classpath $(CLASSPATH) com.example.NativeClass
    $(OUTPUTDIR) should be the output directory where the headers will be generated.
    $(CLASSPATH) should include the classpath needed to find your Java classes.
    Option B: Modify the Configuration Script (configure)
    If the configure script is generating the Makefile, you might need to modify the script itself to use javac -h instead of javah. This involves finding where javah is invoked in the script and replacing it with javac -h.

    Step 3: Update Native Class Declarations
    Ensure that the Native class declarations in your Java source code are correctly annotated with native and have matching methods in your C/C++ code.

    For example, in Java:

    java
    Copy code
    package com.example;

    public class NativeClass {
    public native void nativeMethod();
    }
    In C/C++:

    cpp
    Copy code
    #include "com_example_NativeClass.h"

    JNIEXPORT void JNICALL Java_com_example_NativeClass_nativeMethod(JNIEnv *, jobject) {
    // Implement native method
    }
    Step 4: Compile and Test
    After modifying the Makefile or configure script:

    Clean previous builds: Run make clean to clean up any previous builds.
    Generate headers: Run make to compile your Java classes. The -h option should generate the necessary header files.
    Compile native code: Compile your native code (C/C++) that implements the native methods.
    Test: Run your application to ensure everything works correctly.
    Additional Notes:
    Cross-platform considerations: Ensure any platform-specific configurations or paths are handled correctly for your environment.
    Documentation: Refer to the documentation for your specific version of JDK for any changes or updates related to -h option usage.
    By following these steps, you should be able to upgrade the JCurses Makefile to use the modern mechanism for generating Native class headers using javac -h, allowing you to compile and use the library on your Linux system.

    https://peardrop.social/

Similar Threads

  1. Inconsistency in headers
    By aussiemcgr in forum Java Networking
    Replies: 2
    Last Post: September 6th, 2013, 07:18 PM
  2. Problem Upgrading Tomcat 5.5 to 7.0
    By JohannaQ in forum Web Frameworks
    Replies: 0
    Last Post: June 11th, 2012, 04:47 PM
  3. Help with a makefile (javacc)
    By dethtrain in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 10th, 2011, 03:59 AM
  4. How to remove all Headers from a MimeMessage
    By ArgyrisV in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 8th, 2011, 12:38 PM
  5. Help with Linux makefile
    By ruerric in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 10th, 2010, 10:07 AM

Tags for this Thread