没有java代码的内置war文件

时间:2018-02-23 00:54:07

标签: java windows maven jboss jax-rs

我正在按照以下步骤(由某人提供)在Windows上的JBOSS上部署war文件,如下所示:

1)我创建了一个文件夹Verson3

2)使用Windows命令提示符,我进入了文件夹Version3

3)我运行了以下命令并获得了BUILD SUCCESS

Y:\myusername\My Documents>cd Version3

Y:\myusername\My Documents\Version3>mvn archetype:generate -DgroupId=com.pkg.DownloadService -DartifactId=DownloadService -DarchetypeArtifactId=maven-archetype-we
bapp -DinteractiveMode=false

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: Y:\myusername\My Documents\Version3
[INFO] Parameter: package, Value: com.pkg.DownloadService
[INFO] Parameter: groupId, Value: com.pkg.DownloadService
[INFO] Parameter: artifactId, Value: DownloadService
[INFO] Parameter: packageName, Value: com.pkg.DownloadService
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: Y:\myusername\My 

    Documents\Version3\DownloadService
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 12.262 s
    [INFO] Finished at: 2018-02-22T17:16:11-06:00
    [INFO] Final Memory: 15M/161M
    [INFO] ------------------------------------------------------------------------

这生成了以下目录结构:

Version3
|-- src
|   `-- main
|       |-- resources
|       `-- webapp
|           |-- WEB-INF
|           |   `-- web.xml
|           `-- index.jsp
`-- pom.xml

4)接下来,我被要求添加以下内容并从pom.xml

中删除与JUnit相关的依赖关系代码
<repositories>
       <repository>
          <id>JBoss repository</id>
          <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
       </repository>
</repositories>
  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>  
  <dependencies>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <version>2.3.2.Final</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0</version>
    </dependency>
  </dependencies>

5)我做的另一个改变是web.xml

<!-- Auto scan REST service -->
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- this need same with resteasy servlet url-pattern -->
    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

6)执行以下命令:pom文件所在的mvn clean package。这创建了target文件夹和war文件等。

我想知道的是,根据我收到的说明,我在上述过程中的任何地方都没有使用任何java文件。但我确实有一个java文件 定义了JAXRS Web服务,该文件中提到的包名称为com.pkg.DownloadService。我想知道我是否应该考虑放置它 文件夹DownloadService内的java文件,然后运行上述所有命令?因为在没有任何Web服务的情况下构建war文件对我来说没有意义。

1 个答案:

答案 0 :(得分:1)

您应将DownloadService.java放在src / main / java / com / pkg下。按照目录结构,它看起来像:

Version3
|-- src
|   `-- main
|       |-- java
|       |   `-- com
|       |       `-- pkg
|       |           `-- DownloadService.java
|       |-- resources
|       `-- webapp
|           |-- WEB-INF
|           |   `-- web.xml
|           `-- index.jsp
`-- pom.xml