Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:47:20+00:00 2026-06-12T14:47:20+00:00

Here is the situation: I have a client’s java project open in eclipse. It

  • 0

Here is the situation:

I have a client’s java project open in eclipse. It uses a JNI library created by an Xcode Objective C project. Is there any good way for me to debug the C code from eclipse when I execute the Java code? Obviously eclipse’s default debugger cannot step into the jni library file and we lose the thread (thread meaning investigative thread here, not programming thread).

Any advice or input is appreciated as the code base is large enough that following the client’s code will be radically faster than other options.

Thanks.

EDIT:

It should be noted that the reason that the jni library is written in Objective-C is because it is integrating with Mac OSX. It is using the Cocoa framework to integrate with the Apple speech api.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:47:21+00:00Added an answer on June 12, 2026 at 2:47 pm

    I am not sure that I have fully understood your setup and if you require this to be done from eclipse or not. Anyhow I was interested in doing a little test program using JNI and a Cocoa library doing nothing just to try the debugging of the obj-c/c code.

    I succeeded to do this setup and also to debug the code. I use IntelliJ for Java and Xcode for the objc/c part but doing the java part in eclipse is a no-brainer.

    So you should be able to set up exactly my project structure and get going with the debugging. And from there you should be able to apply this knowledge to your own more complex code.

    This is how I started off:

    • Create a new project in Xcode by choosing Cocoa Library.

    Cocoa Library

    • Name the project libnative and make it of Type Dynamic.

    Choose Options

    • Choose a place for your new project. I use ~/Development/ and skip the Create local git... part.

    • This will create a new project called lib native.xcodeproj in your selected folder. Two files have been automatically created: libnative.h and libnative.m.

    • First you must change the Project Settings.

      • Executable Extension in the Packaging section must be changed from dynlib to jnilib.
      • Framework Search Paths in the Search Paths section must be updated to point to the JNI framework: /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaNativeFoundation.framework/

    enter image description here

    • Now its time to add some code. Be aware that with this setup you will have to use <JavaVM/jni.h>. Update the libnative.m to look like the following code:

    //
    //  libnative.m
    //  libnative
    //
    //  Created by maba on 2012-10-09.
    //  Copyright (c) 2012 maba. All rights reserved.
    //
    
    #import "libnative.h"
    #include <JavaVM/jni.h>
    
    @implementation libnative
    
    @end
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    #ifndef VEC_LEN
    #define VEC_LEN(v) (sizeof(v)/sizeof(v[0]))
    #endif/*VEC_LEN*/
    
    static JavaVM *javaVM;
    
    static void print();
    
    static JNINativeMethod Main_methods[] =
    {
        { "print", "()V", (void*)print },
    };
    
    static struct {
        const char      *class_name;
        JNINativeMethod *methods;
        int             num_methods;
    } native_methods[] = {
        { "com/stackoverflow/Main", Main_methods, VEC_LEN(Main_methods) },
    };
    
    JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
        JNIEnv *env = 0;
        jclass cls  = 0;
        jint   rs   = 0;
    
        if ((*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_4)) {
            return JNI_ERR;
        }
    
        javaVM = jvm;
    
        for (unsigned int i = 0; i < VEC_LEN(native_methods); i++) {
            cls = (*env)->FindClass(env, native_methods[i].class_name);
            if (cls == NULL) {
                return JNI_ERR;
            }
            rs = (*env)->RegisterNatives(env, cls, native_methods[i].methods, native_methods[i].num_methods);
            assert(rs == JNI_OK);
        }
    
        return JNI_VERSION_1_4;
    }
    
    static void print(JNIEnv *env, jclass cls) {
        printf("Hello from C");
    }
    
    #ifdef __cplusplus
    }
    #endif
    
    • Build the code by pressing ⌘+B.

    • And now it is time to create the Java code. I simply created a class called Main in package com.stackoverflow.

    com.stackoverflow.Main.java

    package com.stackoverflow;
    
    /**
     * @author maba, 2012-10-09
     */
    public class Main {
    
        static native void print();
    
        static {
            System.out.println(System.getProperty("java.library.path"));
            System.loadLibrary("native");
        }
    
        public static void main(String[] args) {
            System.out.println("Loading native");
            Main.print();
        }
    }
    
    • Set a breakpoint on the line before Main.print();. Start the debugger with the following JVM option:

    -Djava.library.path="/Users/maba/Library/Developer/Xcode/DerivedData/libnative-cquleqohzyhghnercyqdwpnznjdf/Build/Products/Debug/"
    

    This line is a little long and also user specific. You will have to look for yourself what the directory names are but they will be more or less the same as mine except for the generated libnative-cquleqohzyhghnercyqdwpnznjdf path.

    • The program should be running and waiting at the breakpoint. Time to attach the Xcode debugger to the running application.

    • Choose menu Product -> Attach to Process > and point to the running java process in the System part of the drop down. If there are several java processes then it is most likely the one with the highest PID but not always. You’ll have to try.

    • Create a breakpoint in the c code on the line printf("Hello from C");.

    • Go back to the Java IDE and continue the execution from where it was halting.

    • Go back to Xcode and see that it is waiting at the breakpoint!

    At Breakpoint


    As I stated earlier this is a very simple approach to the obj-c/JNI and your project is probably quite large but with this small test project you can at least see how it works and then continue to your own project setup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a specific java client library. Here is the situation:
Here is my situation: I have a C project linking with many libraries (I
Here is the situation.... I have a iframe, which is located to my client
I have created JAVA GUI that will receive text file(.txt) from other client and
Here's the situation: I have a client who's issued me an XML schema, and
Here is the situation : we have to offer a customer with a web-based
Here is my situation: I have one table that contains a list of drugs
here's the situation: I have a where in every cell all the area has
Here's the situation I have a webpage which has one drop down called prefer.
Here's the situation: I have a two images that are over 1024 in width

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.