1. 更新Pom连带更新其他,添加graalVM打包
This commit is contained in:
parent
f1dc9ca1f7
commit
b5e4c7ca6e
86
pom.xml
86
pom.xml
|
@ -12,9 +12,25 @@
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
|
<java.version>21</java.version>
|
||||||
|
<graalvm.version>23.1.0</graalvm.version>
|
||||||
|
<native.maven.plugin.version>0.10.1</native.maven.plugin.version>
|
||||||
|
<start-class>org.aohe.Main</start-class>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-net</groupId>
|
||||||
|
<artifactId>commons-net</artifactId>
|
||||||
|
<version>3.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-to-slf4j</artifactId>
|
||||||
|
<version>2.23.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.googlecode.jfreesane</groupId>
|
<groupId>com.googlecode.jfreesane</groupId>
|
||||||
<artifactId>jfreesane</artifactId>
|
<artifactId>jfreesane</artifactId>
|
||||||
|
@ -42,6 +58,74 @@
|
||||||
<version>1.18.30</version>
|
<version>1.18.30</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.build.finalName}</finalName>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>${start-class}</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.graalvm.buildtools</groupId>
|
||||||
|
<artifactId>native-maven-plugin</artifactId>
|
||||||
|
<version>${native.maven.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<skip>false</skip>
|
||||||
|
<useArgFile>false</useArgFile>
|
||||||
|
<imageName>${project.artifactId}</imageName>
|
||||||
|
<mainClass>${start-class}</mainClass>
|
||||||
|
<buildArgs>
|
||||||
|
--no-fallback
|
||||||
|
-H:-CheckToolchain
|
||||||
|
</buildArgs>
|
||||||
|
<!-- GraalVM 可达性元数据支持 -->
|
||||||
|
<!-- https://github.com/oracle/graalvm-reachability-metadata -->
|
||||||
|
<metadataRepository>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</metadataRepository>
|
||||||
|
<!--
|
||||||
|
<agent>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</agent>
|
||||||
|
-->
|
||||||
|
</configuration>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<!-- [WARNING] 'native:build' goal is deprecated. Use 'native:compile-no-fork' instead. -->
|
||||||
|
<goal>compile-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>package</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,7 +1,29 @@
|
||||||
package org.aohe;
|
package org.aohe;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import au.com.southsky.jfreesane.SaneDevice;
|
||||||
|
import au.com.southsky.jfreesane.SaneException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aohe.core.sane.utils.SaneSessionUtils;
|
||||||
|
import org.aohe.core.utils.SystemUtils;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello world!");
|
log.info(" 当前系统类型: {}", SystemUtils.getOsName());
|
||||||
|
List<SaneDevice> deviceList;
|
||||||
|
try {
|
||||||
|
deviceList = SaneSessionUtils.getSaneDrivers();
|
||||||
|
} catch (IOException | SaneException e) {
|
||||||
|
log.info(" 获取驱动报错 {}", e.getMessage());
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
for (SaneDevice sane : deviceList){
|
||||||
|
log.info(sane.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,9 +17,14 @@ public class RemoteConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RemoteConfig getInstance(){
|
public static RemoteConfig getInstance(){
|
||||||
String ip = new Setting("config.setting").get("ip");
|
String setIp;
|
||||||
if(ip != null){
|
try {
|
||||||
return new RemoteConfig(ip);
|
setIp = new Setting("config.setting").get("ip");
|
||||||
|
}catch (Exception e){
|
||||||
|
setIp = "127.0.0.1";
|
||||||
|
}
|
||||||
|
if(setIp != null){
|
||||||
|
return new RemoteConfig(setIp);
|
||||||
}
|
}
|
||||||
return new RemoteConfig();
|
return new RemoteConfig();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class SaneSessionUtils {
|
||||||
if (saneSession == null) {
|
if (saneSession == null) {
|
||||||
synchronized(lock){
|
synchronized(lock){
|
||||||
if (saneSession == null) {
|
if (saneSession == null) {
|
||||||
log.info("jFreeSaneConfig:" + JSON.toJSONString(remoteConfig));
|
log.info("jFreeSaneConfig:{}", JSON.toJSONString(remoteConfig));
|
||||||
InetAddress address = InetAddress.getByName(remoteConfig.getIp());
|
InetAddress address = InetAddress.getByName(remoteConfig.getIp());
|
||||||
saneSession = SaneSession.withRemoteSane(address);
|
saneSession = SaneSession.withRemoteSane(address);
|
||||||
log.info("初始化saneSession完成,状态:{}", saneSession != null);
|
log.info("初始化saneSession完成,状态:{}", saneSession != null);
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
package org.aohe.core.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class IpUtil {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输出二进制
|
||||||
|
* @param n
|
||||||
|
*/
|
||||||
|
public static void binaryToDecimal(long n){
|
||||||
|
for(int i = 63;i >= 0; i--) {
|
||||||
|
System.out.print(n >>> i & 1);
|
||||||
|
}
|
||||||
|
System.out.println("---->");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 把 xx.xx.xx.xx 类型的转为 long 类型的
|
||||||
|
*
|
||||||
|
* @param ip
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Long getIpFromString(String ip)
|
||||||
|
{
|
||||||
|
// 进制 2^8 = 256 共四段
|
||||||
|
long ipLong = 0L;
|
||||||
|
String ipTemp = ip;
|
||||||
|
ipLong = Long.parseLong(ipTemp.substring(0, ipTemp.indexOf('.')));
|
||||||
|
ipTemp = ipTemp.substring(ipTemp.indexOf('.') + 1);
|
||||||
|
ipLong = ipLong * 256
|
||||||
|
+ Long.parseLong(ipTemp.substring(0, ipTemp.indexOf('.')));
|
||||||
|
ipTemp = ipTemp.substring(ipTemp.indexOf(".") + 1);
|
||||||
|
ipLong = ipLong * 256
|
||||||
|
+ Long.parseLong(ipTemp.substring(0, ipTemp.indexOf('.')));
|
||||||
|
ipTemp = ipTemp.substring(ipTemp.indexOf('.') + 1);
|
||||||
|
ipLong = ipLong * 256 + Long.parseLong(ipTemp);
|
||||||
|
return ipLong;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 把 long 类型的 Ip 转为一般 Ip 类型:xx.xx.xx.xx
|
||||||
|
*
|
||||||
|
* @param ip
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getIpFromLong(Long ip)
|
||||||
|
{
|
||||||
|
String s1 = String.valueOf((ip & 4278190080L) / 16777216L); // 255.0.0.0 ~ 1.0.0.0 截取第一个八位
|
||||||
|
String s2 = String.valueOf((ip & 16711680L) / 65536L); // 0.255.0.0 ~ 0.1.0.0 截取第二个八位
|
||||||
|
String s3 = String.valueOf((ip & 65280L) / 256L); // 0.0.255.0 ~ 0.0.1.0 截取第三个八位
|
||||||
|
String s4 = String.valueOf(ip & 255L); // 0.0.0.255 ~ 0.0.0.1 截取第四个八位
|
||||||
|
return s1 + "." + s2 + "." + s3 + "." + s4;
|
||||||
|
}
|
||||||
|
public static class NetInfo{
|
||||||
|
private static final long VALIDATE_DATA = Long.MAX_VALUE>>31;
|
||||||
|
private static final HashMap<Integer,String> NET_MASK = new HashMap<>();
|
||||||
|
private static String IP_REGEX = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
|
||||||
|
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." +"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
|
||||||
|
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
|
||||||
|
// ip
|
||||||
|
private String ipStr;
|
||||||
|
private Long ip;
|
||||||
|
// 掩码
|
||||||
|
private String maskStr;
|
||||||
|
private Long mask;
|
||||||
|
// 网段
|
||||||
|
private String segmentStr;
|
||||||
|
private Long segment;
|
||||||
|
// 广播地址
|
||||||
|
private String broadcastStr;
|
||||||
|
private Long broadcast;
|
||||||
|
// 开始 ip
|
||||||
|
private String startIpStr;
|
||||||
|
private Long startIp;
|
||||||
|
// 结束 ip
|
||||||
|
private String endIpStr;
|
||||||
|
private Long endIp;
|
||||||
|
// 可用 ip 数
|
||||||
|
private Long count;
|
||||||
|
// 初始化掩码
|
||||||
|
static{
|
||||||
|
NET_MASK.put(32,getIpFromLong(VALIDATE_DATA));
|
||||||
|
for(int i=1;i<32;i++) {
|
||||||
|
NET_MASK.put(32-i,getIpFromLong(VALIDATE_DATA << i & VALIDATE_DATA));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public NetInfo(String ipStr, String maskStr) {
|
||||||
|
this.ipStr = ipStr;
|
||||||
|
this.maskStr = maskStr;
|
||||||
|
checkParam();
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
public NetInfo(String ipStr, int mask) {
|
||||||
|
this(ipStr,NET_MASK.get(mask));
|
||||||
|
}
|
||||||
|
public void checkParam(){
|
||||||
|
if(maskStr == null
|
||||||
|
|| "".equals(maskStr.trim())
|
||||||
|
|| !NET_MASK.containsValue(maskStr)){
|
||||||
|
throw new RuntimeException("掩码无效");
|
||||||
|
}
|
||||||
|
if(ipStr == null || "".equals(ipStr.trim())){
|
||||||
|
throw new RuntimeException("ip 地址为空");
|
||||||
|
}
|
||||||
|
// 判断 ip 地址是否与正则表达式匹配
|
||||||
|
if (!ipStr.matches(IP_REGEX)) {
|
||||||
|
throw new RuntimeException("IP 地址不合规范");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void init(){
|
||||||
|
this.ip = getIpFromString(ipStr);
|
||||||
|
this.mask = getIpFromString(maskStr);
|
||||||
|
// 网段 = ip & 掩码
|
||||||
|
this.segment = this.ip & this.mask;
|
||||||
|
this.segmentStr = getIpFromLong(this.segment);
|
||||||
|
// 广播地址 网段末尾用 1 补齐
|
||||||
|
this.broadcast = this.segment | (~this.mask & VALIDATE_DATA);
|
||||||
|
binaryToDecimal(broadcast);
|
||||||
|
this.broadcastStr = getIpFromLong(this.broadcast);
|
||||||
|
// 开始地址 网段+1
|
||||||
|
this.startIp = this.segment +1;
|
||||||
|
this.startIpStr = getIpFromLong(this.startIp);
|
||||||
|
// 结束地址 广播地址-1
|
||||||
|
this.endIp = this.broadcast -1;
|
||||||
|
this.endIpStr = getIpFromLong(this.endIp);
|
||||||
|
/*for( long i = startIp;i< endIp;i++){
|
||||||
|
System.out.println(getIpFromLong(i + 1));
|
||||||
|
}*/
|
||||||
|
this.count = this.broadcast - this.startIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIp() {
|
||||||
|
return ipStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMask() {
|
||||||
|
return maskStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSegment() {
|
||||||
|
return segmentStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBroadcast() {
|
||||||
|
return broadcastStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStartIp() {
|
||||||
|
return startIpStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEndIp() {
|
||||||
|
return endIpStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.aohe.core.sane.utils;
|
package org.aohe.core.utils;
|
||||||
|
|
||||||
public class SystemUtils {
|
public class SystemUtils {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
ip = 127.0.0.1
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<!-- 日志存放路径 -->
|
||||||
|
<property name="log.path" value="~/Logs/ScanService"/>
|
||||||
|
<!-- 日志输出格式 -->
|
||||||
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 全部日志输出 -->
|
||||||
|
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/scanService.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
<totalSizeCap>20GB</totalSizeCap>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统模块日志级别控制 -->
|
||||||
|
<logger name="com.aohe" level="info"/>
|
||||||
|
<!-- Spring日志级别控制 -->
|
||||||
|
<logger name="org.springframework" level="warn"/>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
<appender-ref ref="file"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
|
|
Loading…
Reference in New Issue