从maven-antrun-plugin运行的Ant在Java 9上找不到脚本引擎

时间:2017-03-28 10:44:01

标签: maven java-9 maven-antrun-plugin

我有一个使用Ant构建文件的Maven项目:

<?xml version='1.0' encoding='UTF-8'?>
<project>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>my-test-app</artifactId>
   <groupId>my-test-group</groupId>
   <version>1.0-SNAPSHOT</version>

   <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
               <execution>
                  <id>compile</id>
                  <phase>compile</phase>
                  <configuration>
                     <target>
                        <ant antfile="build.xml" inheritRefs="true">
                           <target name="all"/>
                        </ant>
                     </target>
                  </configuration>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
</project>

Ant构建文件使用脚本:

<?xml version='1.0' encoding='UTF-8'?>
<project name="scriptdef-test-build">
   <scriptdef name="test-script" language="javascript">
      <![CDATA[
           var System = Java.type('java.lang.System');
           System.out.println("Working!");
        ]]>
   </scriptdef>
   <target name="all">
      <test-script/>
   </target>
</project>

在Java 8上它可以工作,但在Java 9(9-ea + 162)上它无法找到脚本引擎:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (compile) on project my-test-app: An Ant BuildException has occured: The following error occurred while executing this line:
/home/dan/scriptdef-test/build.xml:10: Unable to create javax script engine for javascript
around Ant part ...<ant antfile="build.xml" inheritRefs="true">... @ 4:47 in /home/dan/scriptdef-test/target/antrun/build-main.xml
...    
Caused by: /home/dan/scriptdef-test/build.xml:10: Unable to create javax script engine for javascript
    at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:84)
    at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:67)
    at org.apache.tools.ant.taskdefs.optional.script.ScriptDef.executeScript(ScriptDef.java:350)
    at org.apache.tools.ant.taskdefs.optional.script.ScriptDefBase.execute(ScriptDefBase.java:50)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:547)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
    ... 34 more

我附加了一个调试器,我发现ScriptEngineManager使用的JavaxScriptRunner没有任何脚本引擎,因为它使用的服务加载器找不到任何ScriptEngineFactory实现。如何让服务加载器工作?

更新:我还为此创建了一个问题:https://issues.apache.org/jira/browse/MANTRUN-200

1 个答案:

答案 0 :(得分:1)

我的解决方法是将脚本更改为Groovy,但是我收到有关此问题的通知,然后回过头来看看问题是否已解决。它不是固定的,但有一条评论使我找到了可行的解决方案:

import pandas as pd
sapmle2000submission_series = pd.Series(sapmle2000submission, dtype='int32')