我该如何打包spring boot项目,那么我可以在c编写的jni程序中使用它吗?

时间:2018-02-12 08:50:55

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

我创建了一个简单的弹簧启动项目,如下所示:

public static void main(String[] args )
{
    SpringApplication app = new SpringApplication(Main.class);
    app.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableApplicationContext ctx = app.run(args);
    System.out.println("serv main");
}

打包

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>com.gutongfei.lab.Main</mainClass>
                </manifest>
            </archive>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

最后我在jni中使用它:

JNIEnv *env;
JavaVMInitArgs vmArgs;
JavaVMOption options[3];

vmArgs.version             = JNI_VERSION_1_2;
vmArgs.ignoreUnrecognized  = JNI_TRUE;
vmArgs.nOptions            = 0;

char classpath[1024]    = "-Djava.class.path=fishnet.jar";//build by maven

options[0].optionString = strcat(classpath, classPath);
vmArgs.nOptions++;

options[1].optionString = "abort";
options[1].extraInfo    = (void *)&myAbortHook;
vmArgs.nOptions++;
options[2].optionString = "exit";
options[2].extraInfo    = (void *)&myExitHook;
vmArgs.nOptions++;

vmArgs.options          = options;
jint res    = JNI_CreateJavaVM(&sJvm, (void **)&env, &vmArgs);
jclass argClass  = (*env)->FindClass(env, "FishnetArg");
jmethodID   cid = (*env)->GetMethodID(env, argClass,"<init>", "()V");
(*env)->CallStaticVoidMethod(env, entreeClass, inputMid,argObj);
...

但是,它失败并出现错误: 无法处理配置类的导入候选[com.gutongfei.lab.Main];嵌套异常是java.lang.IllegalArgumentException:在META-INF / spring.factories中找不到自动配置类。

我的问题是我应该如何构建spring boot项目,然后我可以在jni程序中使用它?

0 个答案:

没有答案