4

Is there any tutorial for using DukeScript with Eclipse? I can find only a description for using with NetBeans.

Horcrux7
  • 23,758
  • 21
  • 98
  • 156

3 Answers3

1

Now I've spent a few hours trying to run a Dukescript project. Not being a NetBeans user, I generated a project from the Maven archetype and then I tried to import it into Eclipse. One problem is that m2eclipse gets confused by the html4j-maven-plugin, it doesn't know in which phase of the build lifecycle it has to run (as far as I understand). So I've added this:

  <pluginManagement>
<plugins>
  <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
  <plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
    <configuration>
        <lifecycleMappingMetadata>
            <pluginExecutions>
                <pluginExecution>
                    <pluginExecutionFilter>
                        <groupId>org.netbeans.html</groupId>
                        <artifactId>
                            html4j-maven-plugin
                        </artifactId>
                        <versionRange>[1.1,)</versionRange>
                        <goals>
                            <goal>process-js-annotations</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action>
                        <execute></execute>
                    </action>
                </pluginExecution>
            </pluginExecutions>
        </lifecycleMappingMetadata>
    </configuration>
  </plugin>
</plugins>

Now m2eclipse doesn't compain. Still, Eclipse doesn't find the Data (model) classes that the plugin generates. So I simply added /target/generated-sources/annotations to the source folder. Perhaps not the most elegant solution, there must a way of doing it in the pom. So, there are no compilation errors. Yet, when I run it I get an exception:

Exception in thread "main" java.util.ServiceConfigurationError: org.netbeans.html.boot.spi.Fn$Presenter: Provider org.netbeans.html.boot.fx.FXPresenter could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:224)
at java.util.ServiceLoader.access$100(ServiceLoader.java:181)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:377)
at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
at net.java.html.boot.BrowserBuilder.showAndWait(BrowserBuilder.java:275)
at javelin.Main.main(Main.java:14)
Caused by: java.lang.UnsupportedClassVersionError: javafx/application/Platform : Unsupported major.minor version 52.0

It looks perhaps like a mismatch between target bytecode and runtime. I'll update this answer if I figure it out.

Update

Success! I've set java compile source and target to 8

      <configuration>
          <source>1.8</source>
          <target>1.8</target>
      </configuration>

And also for the java runtime in .project

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">

There was one last thing to do and it was setting the "browser.rootdir" property so that the app could find the web resources. Just for testing:

String userdir = System.getProperty("user.dir") + "/src/main/webapp";
System.setProperty("browser.rootdir", userdir ); 

I can open the page now and start the animation but I can't stop it due to other errors. Anyway, it's a start.

Update 2

I've managed to get Eclipse to process DukeScript annotations and generate sources using this plugin: m2e-apt. There's one more thing to add to the pom for the plugin to work:

<plugin>   
   <groupId>org.bsc.maven</groupId>   
      <artifactId>maven-processor-plugin</artifactId>   
      <version>2.2.4</version>   
      <executions>   
         <execution>   
           <id>process</id>   
             <goals>   
               <goal>process</goal>   
             </goals>   
             <configuration>
                <outputDirectory>target/generated-sources/annotations</outputDirectory>
            </configuration> 
          </execution>   
        </executions>   
        <dependencies>   
          <dependency>
            <groupId>org.netbeans.html</groupId>
            <artifactId>html4j-maven-plugin</artifactId>
            <version>${net.java.html.version}</version>
          </dependency>
         </dependencies>   
</plugin> 
ZiglioUK
  • 2,573
  • 4
  • 27
  • 32
  • One problem: make sure under Maven/Annotation Processing you choose "Experimental: Delegate Annoation Processing to maven plugin", because if I leave it to JDT, there are errors in the generated code. One drawback is that if the code generation fails for some reasons, Eclipse is unaware. That would show up as a native linkage error at runtime. In this case I have to recompile with Maven from the command line, that fails and shows errors in case of problems – ZiglioUK Jun 03 '15 at 22:48
  • Setting Java source and target to 1.8 is not strictly necessary but it has to match what Eclipse runs on, so if you set it to 1.7, somehow m2e will set the project to run using the jre7 library. Depending on what you run Eclipse with. I run it with jre8, so I had to manually switch the project to use the runtime that matches Eclipse, or I had to set the project target to 1.8. That will be an issue in case of targetting Android – ZiglioUK Jun 03 '15 at 22:51
  • I've just tried with the new Eclipse Mars release. It still works. Make sure Eclipse is launched using a JDK distribution not JRE, as the Maven annotation processor needs tools.jar. Add at the top of eclipse.ini, something like -vm C:\Program Files\Java\jdk1.8.0_45\bin – ZiglioUK Jun 24 '15 at 23:06
1

These issues are similar to those raised during usability review. The way to work around such compilation errors is to switch to command line and do "mvn clean install" that works properly. Configuring Eclipse is possible to some extend and you seem to have found the right way.

Jaroslav Tulach
  • 519
  • 4
  • 7
  • While trying to get the plugin to work with Eclipse, I've run in all sorts of strange situations. It's not clear to me what happens to the javascript code, sometimes a file under META-INF is created, but that breaks something. Also the code generator would generate broken code under some circumstances, not sure why. The whole Maven phase/goal lifecycle is a bit of mistery to me. I'll see if I can put an example project on GitHub – ZiglioUK Jun 02 '15 at 05:03
0

Update: I wrote a short tutorial. Please let me know if it works for you, and what needs to be improved.

monacotoni
  • 606
  • 5
  • 18
  • Actually here's a problem: every time I access "native" javascript methods, I get a java.lang.UnsatisfiedLinkError exception. That's a typical error of JNI whenever native libraries can't be found. Any suggestion there @eppleton? – ZiglioUK May 30 '15 at 11:47
  • Somehow it now works after rebuilding it clean from the command line and also executing it from there. I'm stepping through AbstractFXPresenter.defineJSFn() – ZiglioUK May 31 '15 at 06:06