无法解析符号:import org.eclipse.jetty.server.Server;

时间:2019-03-14 13:44:15

标签: vaadin maven-3 jetty-8

在我的Vaadin码头Maven项目中:

 <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-core</artifactId>
        </dependency>

        <!-- Added to provide logging output as Flow uses -->
        <!-- the unbound SLF4J no-operation (NOP) logger implementation -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.2</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-webapp</artifactId>
            <version>8.1.7.v20120910</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>8.1.7.v20120910</version>
        </dependency>
    </dependencies>

在我的Main.java中:

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.resource.Resource;

public class Main {
    public static void main(String[] args) throws Exception {
        Server server = new Server();

        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(8080);
        server.addConnector(connector);

        ProtectionDomain domain = Main.class.getProtectionDomain();
        URL location = domain.getCodeSource().getLocation();
        WebAppContext webapp = new WebAppContext();
        webapp.setContextPath("/");
        webapp.setWar(location.toExternalForm());
        server.setHandler(webapp);

        server.start();
        server.join();

    }
}

但是我在

中遇到编译错误
import org.eclipse.jetty.server.Server;

Cannot resolve symbol

1 个答案:

答案 0 :(得分:2)

org.eclipse.jetty.server.Server已包含在

<dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>8.1.7.v20120910</version>
</dependency>

我创建了一个Vaadin8小项目,

mvn -B archetype:generate \
        -DarchetypeGroupId=com.vaadin \
        -DarchetypeArtifactId=vaadin-archetype-application \
        -DarchetypeVersion=8.7.1 \
        -DgroupId=org.test \
        -DartifactId=vaadin-app \
        -Dversion=1.0-SNAPSHOT

并添加了您在问题中提到的依赖项。然后我添加了您的Main class。

我可以毫无问题地进行mvn全新安装,并且可以在IntelliJ中进行编译。

请确保Maven正确下载了所有依赖项。