使用JNA windows系统调用kernel32.dll库, inux系统调用libc.so库
1. 环境
jdk1.7
windows7
centos 7
2. 依赖的jar
本程序需要依赖JNA框架.
jna.jar
3. 接口
import java.util.Date;
public interface JNative {
/**
* 设置系统时间
* @param date Date
*/
public void setLocalTime(Date date);
}
4. windows实现
import java.util.Calendar;
import java.util.Date;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Structure;
public class WindowsImpl implements JNative{
public static class SYSTEMTIME extends Structure {
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}