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

  • SEARCH
  • Home
  • 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 7531623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:13:19+00:00 2026-05-30T05:13:19+00:00

I’m working on OSGI bundle which uses Java native interface. I use this makefile

  • 0

I’m working on OSGI bundle which uses Java native interface. I use this makefile to build the .so module:

#!/usr/bin/make -f
#
# Makefile for native stuff
#

# c files to compile
C_SOURCES   := sqrt.c

# the name of the library to build
LIBNAME     := sqrt

C_SOURCE_DIR    := src
C_GENSOURCE_DIR := src

TARGET_DIR  := ../../../target
C_BUILD_DIR    = $(TARGET_DIR)/native
JAVA_BUILD_DIR = $(TARGET_DIR)/classes

# the name of the file we build
TARGET      = $(JAVA_BUILD_DIR)/META-INF/lib/$(LIB_PREFIX)$(LIBNAME)$(LIB_EXTN)

# find the jdk. if this doesn't work for you, define JAVA_HOME in your
# environment or on the make command line
JAVA_HOME ?= /opt/jdk1.7.0_02

# classpath for javah
JAVAH_CLASSPATH = `cat $(TARGET_DIR)/compile-classpath`

# tools and options
CFLAGS = -Wall -fpic
CPPFLAGS = -I$(C_SOURCE_DIR) -I$(C_GENSOURCE_DIR) -Iinclude \
    -I$(JAVA_HOME)/include
JAVAH = /opt/jdk1.7.0_02/bin/javah
JAVAH_FLAGS += -classpath $(JAVAH_CLASSPATH)
JAVAH_CMD = $(JAVAH) $(JAVAH_FLAGS) $(OUTPUT_OPTION)
LDFLAGS = -shared
LINK.so = $(CC) $(LDFLAGS) $(LD_LIBS)

ifdef DEBUG
CFLAGS += -g
LDFLAGS += -g
endif

# os-dependent bits
UNAME := $(shell uname)

ifeq ($(UNAME),Linux)
LIB_PREFIX = lib
LIB_EXTN = .so
CPPFLAGS += -I$(JAVA_HOME)/include/linux
else
ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
LIB_PREFIX =
LIB_EXTN = .dll
CPPFLAGS += -I$(JAVA_HOME)/include/win32
else
f := $(error Platform $(UNAME) not supported)
endif
endif

# we look in $(C_SOURCE_DIR) for c files...
vpath %.c $(C_SOURCE_DIR)

# convenience variables
C_OBJFILES = $(addprefix $(C_BUILD_DIR)/,$(subst .c,.o,$(C_SOURCES)))

# default target
all: $(TARGET)

# rule to compile the .c files
$(C_BUILD_DIR)/%.o: %.c
    @mkdir -p `dirname $@`
    $(COMPILE.c) $(OUTPUT_OPTION) $<

# link the C objects into a shared library
$(TARGET): $(C_OBJFILES) $(LDLIBS)
    @mkdir -p `dirname $@`
    $(LINK.so) $(OUTPUT_OPTION) $^

# a rule to build the .h file with javah                    
$(C_GENSOURCE_DIR)/org_DX_57_osgi_NB_27_impl_Sqrt.h: $(JAVA_BUILD_DIR)/org/DX_57/osgi/NB_27/impl/Sqrt.class
    rm -f $@                
    $(JAVAH) $(JAVAH_FLAGS) $(OUTPUT_OPTION) org.DX_57.osgi.NB_27.impl.Sqrt

# the .o file depends on the .h file
$(C_BUILD_DIR)/sqrt.o: $(C_GENSOURCE_DIR)/org_DX_57_osgi_NB_27_impl_Sqrt.h

clean::
    rm -f $(C_OBJFILES)
    rm -f $(TARGET)
    rm -f $(C_BUILD_DIR)/jnirules.mak

This Makefile successfully generates header files and compiles .o file. The problem is that when the bundle is compiled the .so file is not packaged insight the bundle.
This is the content of the POM file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.DX_57.osgi.NB_27</groupId>
        <artifactId>NB_27</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>NB_27-impl</artifactId>
    <packaging>bundle</packaging>
    <name>NB_27-impl</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>${pom.groupId}</groupId>
            <artifactId>NB_27-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
       <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
           <id>build-native</id>
            <phase>process-classes</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <property name="native.classpath" refid="maven.compile.classpath" />
                <echo file="${project.build.directory}/compile-classpath" message="${native.classpath}" />
                <exec dir="src/main/native" executable="make" failonerror="true" />
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>

            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Import-Package>${pom.groupId}.api, org.osgi.framework, org.apache.commons.collections, org.apache.commons.collections.buffer</Import-Package>
                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                        <Bundle-Activator>${pom.groupId}.impl.NetworkBridgeApp</Bundle-Activator>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <groupId>org.DX_57.osgi.NB_27</groupId>
</project>

When I replace maven-bundle-plugin and maven-compiler-plugin with maven-assembly-plugin the native library is included into the bundle. How I can create OSGI bundle and include native library during build time?

  • 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-05-30T05:13:21+00:00Added an answer on May 30, 2026 at 5:13 am

    I don’t believe the Maven Bundle Plugin has specific provisions for native code, and I don’t think you need them: all the support you need is already there. You will need

    • to include the native libraries using the <Include-Resource> instruction, and
    • include the Bundle-NativeCode header in the instructions, just as you would when building the manifest by hand.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.