mirror of
https://github.com/wxd-gaming/wxdgaming.boot.git
synced 2026-05-06 14:11:11 +08:00
【优化】js文件
This commit is contained in:
19
pom.xml
19
pom.xml
@@ -110,23 +110,6 @@
|
||||
<version>2.0.13</version>
|
||||
</dependency>
|
||||
<!--日志框架-->
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js-scriptengine</artifactId>
|
||||
<version>24.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js-community</artifactId>
|
||||
<version>24.1.2</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js</artifactId>
|
||||
<version>24.1.2</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-common</artifactId>
|
||||
@@ -533,8 +516,6 @@
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<useUniqueVersions>false</useUniqueVersions>
|
||||
|
||||
@@ -20,15 +20,23 @@
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js-scriptengine</artifactId>
|
||||
<version>24.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.polyglot</groupId>
|
||||
<artifactId>polyglot</artifactId>
|
||||
<version>24.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js-community</artifactId>
|
||||
<version>24.1.2</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js</artifactId>
|
||||
<version>24.1.2</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package wxdgaming.boot.jscript;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.graalvm.polyglot.Value;
|
||||
import wxdgaming.boot.agent.io.FileReadUtil;
|
||||
@@ -8,9 +9,12 @@ import wxdgaming.boot.agent.io.FileUtil;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* js 容器
|
||||
*
|
||||
* @author: wxd-gaming(無心道, 15388152619)
|
||||
* @version: 2022-02-09 17:23
|
||||
**/
|
||||
@Getter
|
||||
public class JScript {
|
||||
|
||||
public static final JScript Default = JScript.build();
|
||||
@@ -58,4 +62,8 @@ public class JScript {
|
||||
return context.getBindings("js").getMember(find);
|
||||
}
|
||||
|
||||
public void putMember(String id, Object value) {
|
||||
context.getBindings("js").putMember(id, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
27
wxdgaming.boot.jscript/src/test/java/test/JavaObject2Js.java
Normal file
27
wxdgaming.boot.jscript/src/test/java/test/JavaObject2Js.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package test;
|
||||
|
||||
import wxdgaming.boot.jscript.JScript;
|
||||
|
||||
/**
|
||||
* java object 类转换成 js
|
||||
*
|
||||
* @author: wxd-gaming(無心道, 15388152619)
|
||||
* @version: 2025-03-03 19:42
|
||||
**/
|
||||
public class JavaObject2Js {
|
||||
|
||||
public static void main(String[] args) {
|
||||
JScript build = JScript.build();
|
||||
build.getContext().getBindings("js").putMember("jlog", new JLog());
|
||||
build.eval4Code("jlog.info('hello world');");
|
||||
}
|
||||
|
||||
public static class JLog {
|
||||
|
||||
public void info(String msg) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user