{"id":2244,"date":"2023-05-07T18:21:07","date_gmt":"2023-05-07T10:21:07","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2244"},"modified":"2023-05-07T18:21:18","modified_gmt":"2023-05-07T10:21:18","slug":"groovy-code-example-specify-name-for-compiled-class-file-of-groovy-script","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/05\/07\/groovy-code-example-specify-name-for-compiled-class-file-of-groovy-script\/","title":{"rendered":"Groovy\u4ee3\u7801\u793a\u4f8b &#8211; \u5982\u4f55\u4e3agroovy\u811a\u672c\u7f16\u8bd1\u540e\u7684class\u6587\u4ef6\u6307\u5b9a\u540d\u5b57\uff1f"},"content":{"rendered":"<p>groovy\u811a\u672c\u9ed8\u8ba4\u4f1a\u88ab\u7f16\u8bd1\u6210<code>Script1.groovy<\/code> &#8230; <code>Script777.groovy<\/code>\u3002\u8fd9\u5bf9\u4e8e\u9519\u8bef\u7684\u5224\u65ad\u975e\u5e38\u4e0d\u5229\uff0c\u4e0d\u8fc7\u6211\u4eec\u53ef\u4ee5\u6307\u5b9a\u811a\u672c\u7f16\u8bd1\u7684\u540d\u79f0\uff0c\u4ece\u800c\u80fd\u591f\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u811a\u672c\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7<code>GroovyClassLoader<\/code>\u6765\u6307\u5b9a\u7f16\u8bd1\u540e\u7684class\u6587\u4ef6\u540d\u79f0<\/p>\n<pre><code class=\"language-java\">GroovyClassLoader groovyClassLoader = new GroovyClassLoader();\nClass&lt;Script&gt; parsedClass = groovyClassLoader.parseClass(scriptText, name); \/\/name \u4e3a\u811a\u672c\u7f16\u8bd1\u540e\u7684\u540d\u5b57\nScript script = scriptClass.newInstance();\nscript.run();  \/\/ \u6267\u884c\u811a\u672c<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>groovy\u811a\u672c\u9ed8\u8ba4\u4f1a\u88ab\u7f16\u8bd1\u6210Script1.groovy &#8230; Script777.groovy\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[568],"tags":[],"class_list":["post-2244","post","type-post","status-publish","format-standard","hentry","category-groovy"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2244"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2244\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}