2

我有一个依赖 C 源文件的 Java 项目。我有正确的 JNI 头文件,我只需要使用 C 代码将它们编译为target/dll中的(或 Linux/OSX 等效项)。我当前的pom.xml构建 Java 代码,但不构建.dll

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <groupId>xyz.jadonfowler</groupId>
    <artifactId>o</artifactId>
    <packaging>jar</packaging>
    <version>2.0</version>
    <properties>
        <!-- Native compiler -->
        <compiler-name>clang</compiler-name>
        <linker-name>clang</linker-name>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.sparkjava</groupId>
            <artifactId>spark-core</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>com.heroku.sdk</groupId>
            <artifactId>heroku-jdbc</artifactId>
            <version>0.1.0</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        </dependency>
    </dependencies>
    <build>
        <defaultGoal>install</defaultGoal>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>src</testSourceDirectory>
        <resources>
            <resource>
                <directory>res</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <optimize>true</optimize>
                    <debug>true</debug>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>xyz.jadonfowler.o.WebIDE</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>xyz.jadonfowler.o.WebIDE</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.alexkasko.maven</groupId>
                <artifactId>jni-headers-maven-plugin</artifactId>
                <version>1.0.6</version>
                <executions>
                    <!-- generate header for native methods -->
                    <execution>
                        <id>javah</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>javah</goal>
                        </goals>
                        <configuration>
                            <javahClass>xyz.jadonfowler.o.OCBindings</javahClass>
                            <javahOutputFilePath>${project.basedir}/xyz_jadonfowler_o_OCBindings.h</javahOutputFilePath>
                        </configuration>
                    </execution>
                    <!-- generate header for java methods -->
                    <!-- Not need atm
                    <execution>
                        <id>javap</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>javap</goal>
                        </goals>
                        <configuration>
                            <javapClass>xyz.jadonfowler.o.OCBindings</javapClass>
                            <javapOutputFilePath>${project.basedir}/my_header_callbacks.h</javapOutputFilePath>
                        </configuration>
                    </execution> -->
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.2.3</version>
                <extensions>true</extensions>
                <configuration>
                    <c>
                        <name>${compiler-name}</name>
                        <debug>false</debug>
                        <includes>
                            <include>*.h</include>
                            <include>*.c</include>
                        </includes>
                        <!-- Options for compiler -->
                        <options combine.children="append">
                            <option>-I $JAVA_HOME</option>
                            <option>-I $JAVA_HOME/*</option>
                        </options>
                    </c>
                    <linker>
                        <name>${linker-name}</name>
                    </linker>
                    <libraries>
                        <library>
                        <type>jni</type>
                        <narSystemPackage>xyz.jadonfowler.o</narSystemPackage>
                        </library>
                    </libraries>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>windows-common</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.maven-nar</groupId>
                        <artifactId>nar-maven-plugin</artifactId>
                        <extensions>true</extensions>
                        <configuration>
                            <cpp>
                                <options combine.children="append">
                                    <option>-mthreads</option>
                                </options>
                            </cpp>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>linux-common</id>
            <activation>
                <os>
                    <family>linux</family>
                </os>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.maven-nar</groupId>
                        <artifactId>nar-maven-plugin</artifactId>
                        <extensions>true</extensions>
                        <configuration>
                            <cpp>
                                <options combine.children="append">
                                    <option>-pthread</option>
                                </options>
                            </cpp>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

我正在使用带有 Clang 的 Java 8。我有jni-headers-maven-plugin,但我认为我不需要它,因为我不需要即时生成标题。我也有nar-maven-plugin,我认为它配置正确,但它没有出现在任何地方的日志中。

4

0 回答 0