使用nar-maven-plugin

时间:2015-05-20 14:59:16

标签: java maven java-native-interface spring-boot

我在我的Spring启动项目中使用了nar-maven-plugin,开发时一切顺利,但是当我运行maven包时,编译顺利进行,直到最后一步抛出错误:

[INFO] 
[INFO] --- nar-maven-plugin:3.2.0:nar-test (default-nar-test) @ customertracker ---
[INFO] Preparing Nar dependencies
[INFO] Unpacking 0 dependencies to /home/diego/Development/Web/Spring/CustomerTracker/target/test-nar
[INFO] 
[INFO] --- nar-maven-plugin:3.2.0:nar-prepare-package (default-nar-prepare-package) @ customertracker ---
[INFO] 
[INFO] --- nar-maven-plugin:3.2.0:nar-package (default-nar-package) @ customertracker ---
[INFO] Building zip: /home/diego/Development/Web/Spring/CustomerTracker/target/customertracker-0.0.1-SNAPSHOT-amd64-Linux-gpp-jni.nar
[INFO] 
[INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ customertracker ---
[INFO] Building jar: /home/diego/Development/Web/Spring/CustomerTracker/target/customertracker-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.2.3.RELEASE:repackage (default) @ customertracker ---
[INFO] Attaching archive: /home/diego/Development/Web/Spring/CustomerTracker/target/customer-tracker-app.nar, with classifier: null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 26.190 s
[INFO] Finished at: 2015-05-20T09:41:16-05:00
[INFO] Final Memory: 32M/401M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage (default) on project customertracker: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: For artifact {com.housingelectronics:customertracker:0.0.1-SNAPSHOT:nar}: An attached artifact must have a different ID than its corresponding main artifact. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

所以我尝试更改spring-boot-maven-plugin和我的nar-maven-plugin输出属性中的fileName属性,但不能正常工作

这是我的maven简化版:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.housingelectronics</groupId>
    <artifactId>customertracker</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>nar</packaging> <-- changing this to jar works but the applications does not find the .so library on runtime -->

    <name>CustomerTracker</name>
    <description>Customer Tracker</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>customertracker.CustomerTrackerApplication</start-class>
        <java.version>1.7</java.version>
    </properties>

    <dependencies>
        ...
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>1.2.1.RELEASE</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <finalName>customer-tracker-app</finalName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.2.0</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <configuration>
                        <output>customer-tracker-nar-generated</output>
                            <cpp>
                                <sourceDirectory>src/main/c++/udevLaserScannerDriverJNI/</sourceDirectory>
                                <includes>
                                    <include>laserscannerlistener.cpp</include>
                                    <include>utils.cpp</include>
                                    <include>netlink/**/*.cc</include>
                                </includes>
                            </cpp>
                            <c>
                                <excludes>
                                    <exclude>**/node_modules/**/*.c</exclude>
                                </excludes>
                            </c>
                            <java>
                                <include>true</include>
                            </java>
                            <javah>
                                <jniDirectory>src/main/c++/udevLaserScannerDriverJNI/</jniDirectory>
                            </javah>
                            <libraries>
                                <library>
                                    <type>jni</type>
                                    <narSystemPackage>customertracker.devices.udev</narSystemPackage>
                                </library>
                            </libraries>
                        </configuration>
                        <!-- <phase>generate-sources</phase> -->
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,我所做的是在spring-boot-maven-plugin中使用分类器选项而不是fileName,它可以工作,这会产生两个nar文件,一个带有spring-boot应用程序,另一个带有另一个使用.so库,现在问题是使用它们来运行应用程序,但这个问题独立于这个线程。