tomcat - javax.servlet 无法解析为 OpenShift Tomcat 7 (JBoss EWS 2.0)

标签 tomcat servlets jboss openshift

我正在为 OpenShift PaaS 构建第一个项目。决定使用 Java,因此下载了 JBoss Developer Studio 并创建了第一个项目。 Openshift 已经创建了模板,所以它应该可以运行。但是在developer studio中,出现错误:

javax.servlet cannot be resolved

我知道这对于 Java EE 人员来说可能很简单,但我的问题是对于 OpenShift,解决方案是否相同。我们可以只复制一个 apache tomcat jar 到项目文件夹吗?我猜 JBoss Develper Studio 不完全是 Eclipse?所以我添加了 jar ,错误消失了。然后有这个警告:

Classpath entry .. tomecat-7.0.42/lib/servlet-api.jar will not be exported or published ClassNotFoundException may result.

问题

错误和警告消失的正确做法是什么? Openshift 应该已经有了 jar,因为它是 PaaS,而不是 IaaS。我们是否只需要 jar 来构建,但这个 jar 不会成为网络应用程序的一部分?

信息

JBoss Developer Studio 确实有 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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>tom</groupId>
    <artifactId>tom</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>tom</name>
    <repositories>
        <repository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.2-1003-jdbc4</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>           
    </dependencies>
    <profiles>
        <profile>
            <!-- When built in OpenShift the 'openshift' profile will be used when 
                invoking mvn. -->
            <!-- Use this profile for any OpenShift specific customization your app 
                will need. -->
            <!-- By default that is to put the resulting archive into the 'webapps' 
                folder. -->
            <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
            <id>openshift</id>
            <build>
                <finalName>tom</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.1.1</version>
                        <configuration>
                            <outputDirectory>webapps</outputDirectory>
                            <warName>ROOT</warName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

最佳答案

artifactId 不同于通常用于引用对 mavenCentral 的依赖项。
对于 OpenShift 的 repo 使用:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

关于tomcat - javax.servlet 无法解析为 OpenShift Tomcat 7 (JBoss EWS 2.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19017720/

相关文章:

java - Tomcat 的 Cookie 是如何工作的?

java - 使用 JNDI 配置 Tomcat 8 和 Shiro

java - Spring Boot Tomcat配置,从容器迁移到嵌入式

java - 如何在本地机器上为远程tomcat服务器制作一个网络应用程序

java - 将请求转发到 JSP

java - HttpServletResponse - 写入响应编写器与输出流

jboss - 更改 Wildfly 管理控制台的上下文根

java - 来自 Google App Engine 的网页中的静态图像

java - 有没有办法在运行时从 JBoss server.xml 读取 jvmRoute 值?

linux - Jboss linux访问windows共享