native-maven-plugin与maven-nar-plugin配置
native-maven-plugin与maven-nar-plugin不一样,不是同一个东西
一.下面讲解windows平台下,native-maven-plugin的使用:
1. vs环境变量设置
要在visual studio 2005 prompt窗口中,VC/bin目录下执行 vsvars32(参看,http://msdn.microsoft.com/en-us/library/f2ccy3wt(v=VS.100).aspx)
并在visual studio 2005 prompt窗口中执行mvn的相关命令
否则出现stdio.h无法找到的问题(hellworld.c中就一句话printf("xxxx"); printf需要使用stdio.h头文件)
2. 目录结构:
native-maven-example
--src
----main
------native
--------helloWorld.c
--target
----objs
--pom.xml
3. pom.xml
- <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>org.developers.blog</groupId>
- <artifactId>maven-native-example</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>exe</packaging>
- <url>http://maven.apache.org</url>
- <name>maven-native-example.uexe</name>
- <properties>
- <native.source.dir>src/main/native</native.source.dir>
- </properties>
- <dependencies>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>native-maven-plugin</artifactId>
- <version>1.0-alpha-7</version>
- <extensions>true</extensions>
- <configuration>
- <compilerProvider>msvc</compilerProvider>
- <envFactoryName>org.codehaus.mojo.natives.msvc.MSVC2005x86EnvFactory</envFactoryName>
- <compilerExecutable>cl</compilerExecutable>
- <linkerExecutable>cl</linkerExecutable>*
- <sources>
- <source>
- <directory>${native.source.dir}</directory>
- <fileNames>
- <fileName>helloWorld.c</fileName>
- </fileNames>
- </source>
- <source>
- <directory>${native.source.dir}/include</directory>
- </source>
- </sources>
- <!--linkerStartOptions>
- <linkerStartOption>-shared</linkerStartOption>
- </linkerStartOptions-->
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project>
<packaging>exe</packaging> //打包的方式
plugin的设置中:
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>1.0-alpha-7</version> 确定了native-plugin的版本
<envFactoryName>org.codehaus.mojo.natives.msvc.MSVC2005x86EnvFactory</envFactoryName> 决定该plugin编译器使用的环境
抓住了这几个,现在看这个pom.xml文件就很简单了,就是对plugin进行配置,设置编译器环境等,还有配置依赖等.