如何正确地将JavaFX 8应用程序迁移到Maven?

时间:2014-04-30 22:47:31

标签: java eclipse maven javafx-8

我最近开始使用Maven(3.x),因为我需要通过Maven存储库轻松获得的ControlsFX库。我为Maven集成安装了m2e插件,并将我的项目转换为Maven项目(配置 - >转换为Maven项目)。

现在,Eclipse(开普勒)以@Override注释警告我,说:

Syntax error, annotations are only available if source level is 1.5 or greater

但目前的代码合规性实际上是1.8。事实上,当我使用" 1快速修复"时,Eclipse会更改这些行:

diff --git a/.classpath b/.classpath
index 9c865fb..0a1dadd 100644
--- a/.classpath
+++ b/.classpath
@@ -12,7 +12,7 @@
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 29b83c5..0648bb1 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,8 @@
 eclipse.preferences.version=1
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.compliance=1.5
 org.eclipse.jdt.core.compiler.debug.lineNumber=generate
 org.eclipse.jdt.core.compiler.debug.localVariable=generate
 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -10,4 +10,4 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
 org.eclipse.jdt.core.compiler.processAnnotations=disabled
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.source=1.5

我的JDK安装是Oracle的标准:

$ java -version                                                              
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

<小时/>

更新

这是我的pom.xml文件的内容:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.tilemup</groupId>
  <artifactId>tilemup</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <properties>
    <jar.final.name>tilemup</jar.final.name>
    <main.class>org.tilemup.Game</main.class>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.controlsfx</groupId>
      <artifactId>controlsfx</artifactId>
      <version>8.0.5</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>${jar.final.name}</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>${main.class}</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

如您所见,指定了<source>1.8</source>。我做错了什么?

2 个答案:

答案 0 :(得分:0)

Eclipse Kepler(4.3.2)不支持Java 8.我必须使用此过程对其进行修补:

https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler

Eclipse Luna(4.4)将拥有本机支持。尽管如此,我还是不明白为什么Eclipse之前没有抱怨过。

答案 1 :(得分:0)

如前所述,Kepler不支持开箱即用的Java 8,但是你可以去搜索eclipse市场(我相信它是一个帮助子菜单),在搜索框中输入java 8.官方java 8 kepler插件会弹出。安装它,你的java 8问题应该消失。

我个人使用Netbeans进行JavaFX项目,但这是我的pom使用java 8支持构建应用程序

           <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>

                    <phase>package</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>${java.home}/../bin/javafxpackager</executable>
                        <arguments>
                            <argument>-createjar</argument>
                            <argument>-nocss2bin</argument>
                            <argument>-appclass</argument>
                            <argument>${mainClass}</argument>
                            <argument>-srcdir</argument>
                            <argument>${project.build.directory}/classes</argument>
                            <argument>-outdir</argument>
                            <argument>${project.build.directory}</argument>
                            <argument>-outfile</argument>
                            <argument>${project.build.finalName}.jar</argument>
                        </arguments>
                    </configuration>
                </execution>
                <execution>
                    <id>default-cli</id>
                    <goals>
                        <goal>exec</goal>                            
                    </goals>
                    <configuration>
                        <executable>${java.home}/bin/java</executable>
                        <commandlineArgs>${runfx.args}</commandlineArgs>
                    </configuration>
                </execution>
            </executions>  
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
        </plugin>