2013-07-29 74 views
0

我已经通过example hello world dropwizard项目工作,它在IntelliJ中显示无错误(我是Eclipse老手但是IntelliJ新手),但通过maven编译失败。IntelliJ中的Java项目没有错误,但编译失败,通过Maven

IntelliJ console

源目录包含:

/src/main/java/com/example/helloworld/HelloWorldConfiguration.java 
/src/main/java/com/example/helloworld/HelloWorldService.java 

其中HelloWorldService样子:

package com.example.helloworld; 

import com.example.helloworld.resources.HelloWorldResource; 
import com.example.helloworld.health.TemplateHealthCheck; 
import com.yammer.dropwizard.Service; 
import com.yammer.dropwizard.config.Bootstrap; 
import com.yammer.dropwizard.config.Environment; 

public class HelloWorldService extends Service<HelloWorldConfiguration> { 
    public static void main(String[] args) throws Exception { 
     new HelloWorldService().run(args); 
    } 

    @Override 
    public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) { 
     bootstrap.setName("hello-world"); 
    } 

    @Override 
    public void run(HelloWorldConfiguration configuration, 
        Environment environment) { 
     final String template = configuration.getTemplate(); 
     final String defaultName = configuration.getDefaultName(); 
     environment.addResource(new HelloWorldResource(template, defaultName)); 
     environment.addHealthCheck(new TemplateHealthCheck(template)); 
    } 

} 

和Maven与回来:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-project: Compilation failure: Compilation failure: 
[ERROR] /Users/markdsievers/IdeaProjects/dropwizard/src/main/java/com/example/helloworld/HelloWorldService.java:[9,48] cannot find symbol 
[ERROR] symbol: class HelloWorldConfiguration 
[ERROR] /Users/markdsievers/IdeaProjects/dropwizard/src/main/java/com/example/helloworld/HelloWorldService.java:[15,38] cannot find symbol 
[ERROR] symbol : class HelloWorldConfiguration 
[ERROR] location: class com.example.helloworld.HelloWorldService 
[ERROR] /Users/markdsievers/IdeaProjects/dropwizard/src/main/java/com/example/helloworld/HelloWorldService.java:[20,21] cannot find symbol 
[ERROR] symbol : class HelloWorldConfiguration 
[ERROR] location: class com.example.helloworld.HelloWorldService 

,其中pom.xml样子:

<?xml version="1.0" encoding="UTF-8"?> 
<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>com.example.helloworld</groupId> 
    <artifactId>my-project</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <dependencies> 
     <dependency> 
      <groupId>com.yammer.dropwizard</groupId> 
      <artifactId>dropwizard-core</artifactId> 
      <version>0.6.2</version> 
     </dependency> 
    </dependencies> 

    <properties> 
     <!-- use UTF-8 for everything --> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <encoding>UTF-8</encoding> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

我从行家得到同样的错误,如果在编译的目标是通过命令行或在运行的IntelliJ。源代码根目录(/ src/main/java)在IntelliJ中设置,并且没有任何清理和重新编译有任何效果。

任何建议表示赞赏。

+0

如果您还包含“HelloWorldConfiguration”的完整源代码,则重现情况会更容易。 (我遇到了与此相关的其他编译问题,没有发现你的设置有任何明显的问题。) – Jonik

+0

极度“太局部化”的答案证明。 –

回答

1

发现问题... HelloWorldConfiguration没有.java扩展名。很邪恶的IMO,IDE将它视为一个有效的java文件,并且是通过New Java Class创建的(或者不能有或者出错)。无论如何,可能需要启用文件扩展名的查看。

+0

这很奇怪,但很好,你得到它的工作。 (我确实很难相信IDEA会在通过IDEA UI正常创建类时忽略“.java”扩展名。) – Jonik

+0

@Jonik是的,彻底弄糊了它是如何进入(并保持在)状态和令人讨厌的IntelliJ代表环境没有错误。感谢您的期待,对于极其本地化的问题感到抱歉。 – markdsievers

相关问题