我尝试将play框架(java版本)与maven和intellij想法集成。 为此,我使用play2-maven-plugin(https://code.google.com/p/play2-maven-plugin/);
我创建了pom文件,如手册中所述。 现在pom文件看起来像这样:
<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.sigmaps</groupId>
<artifactId>afrodita</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>play2</packaging>
<name>Afrodita</name>
<repositories>
<repository>
<id>typesafe</id>
<name>Typesafe - releases</name>
<url>http://repo.typesafe.com/typesafe/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<play2.version>2.3.3</play2.version>
<scala.version>2.10.4</scala.version>
<play2.plugin.version>1.0.0-alpha8</play2.plugin.version>
<sbt-compiler.plugin.version>1.0.0-beta4</sbt-compiler.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play_2.10</artifactId>
<version>${play2.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-java_2.10</artifactId>
<version>${play2.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/app</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/conf</directory>
</resource>
<resource>
<directory>${basedir}</directory>
<includes>
<include>public/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.google.code.play2-maven-plugin</groupId>
<artifactId>play2-maven-plugin</artifactId>
<version>${play2.plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
在intellij Idea中,在Maven项目标签上点击插件=&gt; play2 =&gt; paly2:运行
然后给出错误:
[INFO] [play2:run {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] null
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NullPointerException
at com.google.code.play2.plugin.AbstractPlay2ServerMojo.getProjectClassPath(AbstractPlay2ServerMojo.java:151) [INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Afrodita
[INFO] task-segment: [com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-alpha8:run]
[INFO] ------------------------------------------------------------------------
[INFO] [play2:run {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] null
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NullPointerException
at com.google.code.play2.plugin.AbstractPlay2ServerMojo.getProjectClassPath(AbstractPlay2ServerMojo.java:151)
at com.google.code.play2.plugin.AbstractPlay2ServerMojo.prepareAntJavaTask(AbstractPlay2ServerMojo.java:70)
at com.google.code.play2.plugin.AbstractPlay2RunMojo.internalExecute(AbstractPlay2RunMojo.java:91)
at com.google.code.play2.plugin.AbstractPlay2Mojo.execute(AbstractPlay2Mojo.java:139)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Wed Sep 24 12:41:25 MSK 2014
[INFO] Final Memory: 14M/299M
[INFO] ------------------------------------------------------------------------
Process finished with exit code 1
at com.google.code.play2.plugin.AbstractPlay2ServerMojo.prepareAntJavaTask(AbstractPlay2ServerMojo.java:70)
at com.google.code.play2.plugin.AbstractPlay2RunMojo.internalExecute(AbstractPlay2RunMojo.java:91)
at com.google.code.play2.plugin.AbstractPlay2Mojo.execute(AbstractPlay2Mojo.java:139)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
然后我尝试sbt-compiler =&gt; sbt-compiler:编译,这给了我另一个错误:
[INFO] Building Afrodita
[INFO] task-segment: [com.google.code.sbt-compiler-maven-plugin:sbt-compiler-maven-plugin:1.0.0-beta4:compile]
[INFO] ------------------------------------------------------------------------
[INFO] [sbt-compiler:compile {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An invalid artifact was detected.
This artifact might be in your project's POM, or it might have been included transitively during the resolution process. Here is the information we do have for this artifact:
o GroupID: <<< MISSING >>>
o ArtifactID: sbt-compiler-sbt0135
o Version: <<< MISSING >>>
o Type: jar
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.artifact.InvalidArtifactRTException: For artifact {null:sbt-compiler-sbt0135:null:jar}: The groupId cannot be empty.
at org.apache.maven.artifact.DefaultArtifact.validateIdentity(DefaultArtifact.java:129)
at org.apache.maven.artifact.DefaultArtifact.<init>(DefaultArtifact.java:122)
at org.apache.maven.artifact.factory.DefaultArtifactFactory.createArtifact(DefaultArtifactFactory.java:158)
at org.apache.maven.artifact.factory.DefaultArtifactFactory.createArtifact(DefaultArtifactFactory.java:117)
at org.apache.maven.artifact.factory.DefaultArtifactFactory.createArtifact(DefaultArtifactFactory.java:111)
at org.apache.maven.artifact.factory.DefaultArtifactFactory.createArtifact(DefaultArtifactFactory.java:40)
at com.google.code.sbt.compiler.plugin.AbstractSBTCompileMojo.getResolvedArtifact(AbstractSBTCompileMojo.java:547)
at com.google.code.sbt.compiler.plugin.AbstractSBTCompileMojo.getWellKnownSbtCompiler(AbstractSBTCompileMojo.java:685)
at com.google.code.sbt.compiler.plugin.AbstractSBTCompileMojo.getSbtCompiler(AbstractSBTCompileMojo.java:635)
at com.google.code.sbt.compiler.plugin.AbstractSBTCompileMojo.internalExecute(AbstractSBTCompileMojo.java:287)
at com.google.code.sbt.compiler.plugin.SBTCompileMojo.internalExecute(SBTCompileMojo.java:102)
at com.google.code.sbt.compiler.plugin.AbstractSBTCompileMojo.execute(AbstractSBTCompileMojo.java:247)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
如果我尝试使用激活器运行项目,那就运行正常。 我有什么办法解决这个问题并用maven运行项目,没有SBT?
答案 0 :(得分:0)
play2:run目标的executedProject
参数是可选的。没有使用过play2,我的第一个猜测就是它不是目标所假定的。如果运行mvn ... -e -X
(打印错误和调试信息),您是否看到实际设置的值?
答案 1 :(得分:0)
第一个问题(使用play2) - 在1.0.0-alpha9中,错误消息得到了改进,现在它告诉我在这种情况下要做什么。它是问题https://code.google.com/p/play2-maven-plugin/issues/detail?id=29的一部分,请参阅最后评论。
第二个问题(使用sbt-compiler)在1.0.0-beta5中得到修复 - 请参阅问题https://code.google.com/p/sbt-compiler-maven-plugin/issues/detail?id=14。