markdsievers
markdsievers

Reputation: 7319

Java project in IntelliJ is error free but compilation fails via Maven

I've worked my way through the example hello world dropwizard project which appears error free in IntelliJ (I'm an Eclipse veteran but new to IntelliJ) but compilation fails via maven.

IntelliJ console

The source directory contains:

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

where HelloWorldService looks like:

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));
    }

}

and maven is coming back with:

[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

where the pom.xml looks like:

<?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>

I get the same error from maven if the compile goal is run from the command line or within IntelliJ. Source root (/src/main/java) is set in IntelliJ and no amount of cleaning and recompiling has had any effect.

Any suggestions appreciated.

Upvotes: 1

Views: 1403

Answers (1)

markdsievers
markdsievers

Reputation: 7319

Found the issue... HelloWorldConfiguration did not have a .java extension. Pretty evil IMO, IDE is treating it as a valid java file and was created via the New Java Class (or must not have or something went wrong). Anyways, probably need to enable view of file extensions.

Upvotes: 1

Related Questions