开发者

Putting my JavaFX app in a WAR with Maven

I am trying to make my JavaFX app compile into a WAR file for deployment on a Jetty server, using Maven. The problem, as I see it, is with the javascript in my webapp's index.html:

<script>
    javafx(
        {
              draggable: true,
              width: 600,
              height: 290,
              code: "my.app.package.MyApp",
              name: "MyApp",
              id: "app"
        }
    );
</script>

Of course, JavaScript throws an error, because it's missing the 'archive' parameter where I am supposed to 开发者_如何学Cput the name of the jar file I'm loading this from. But that's the problem, there is no jar. This is a war with .class files in 'WEB-INF/classes/' and not in a jar. There doesn't seem to be much documentation on how to do this.

My concern is that this is unsupported behavior. An annoying alternative is to change the build type to 'jar', build it, change the build type back to 'war', build it, and put the jar in the war by hand every time. I suppose that would be alright if I could find an automated way of doing that, but I wouldn't know how to go all INCEPTION on the build process or if that's even a good idea to try.

Thanks for any ideas!


Classes deployed in WEB-INF/classes are part of your web application and they run on the server. Your JavaFX classes are for a completely separate application that runs in the browser or on a desktop.

You should keep the two of them in separate projects and then use Maven to add the packaged JavaFX jar into your WAR prior to the package phase of the WAR project.


The solution I came to was to build the JavaFX app using an ant task (as it was a NetBeans project anyway) and including the resulting jar in the war by using this configuration for the maven-war-plugin:

<configuration>
  <webResources>
    <!-- Include the jar build inside the war -->
    <resource>
      <directory>dist</directory>
      <includes>
        <include>MyJavaFXApp.jar</include>
      </includes>
    </resource>
  </webResources>
</configuration>

For those looking for a pure-maven solution, instead of an ant task, I was also able to use the maven-jar-plugin to specifically build a jar (the project packaging type still 'war') as well, which I then include with the method included above.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
      <execution>
        <id>make-a-jar</id>
        <phase>compile</phase>
        <goals>
          <goal>jar</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜