简体   繁体   English

如何从IntelliJ获取运行本地服务器的Maven项目

[英]How to get maven project running local server from IntelliJ

Early stages of understanding Java development. 了解Java开发的早期阶段。 I have created a new Maven project in IntelliJ (not used an archetype). 我已经在IntelliJ中创建了一个新的Maven项目(未使用原型)。

So far I have added a folder called src/main/webapp and dropped an index.jsp file in there that has some sample code that prints "hello world" to the screen. 到目前为止,我已经添加了一个名为src / main / webapp的文件夹,并在其中放置了index.jsp文件,该文件中包含一些示例代码,可在屏幕上显示“ hello world”。

I then examined some example pom.xml files and attempted to create my own that would allow me to at least run my app locally: 然后,我检查了一些示例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>romac</groupId>
    <artifactId>connect-parent</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <jdk.version>1.8</jdk.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>romac-connect</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.11.v20180605</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <stopKey>STOP</stopKey>
                    <stopPort>8005</stopPort>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

I'm then unsure how to run my project with Jetty or with Google Cloud Tools. 然后,我不确定如何使用Jetty或Google Cloud Tools运行我的项目。 I'm developing for Google App Engine Standard so which is preferable for using as local server? 我正在开发Google App Engine标准版,因此哪个更适合用作本地服务器? how do I get it to run from IntelliJ UI? 如何从IntelliJ UI运行它?

Since you are developing for App Engine standard, you are correct to use Google Cloud Tools for IntelliJ , which provides an App Engine specific local dev server. 由于您是针对App Engine标准开发的,因此正确使用IntelliJ的Google Cloud Tools ,它提供了App Engine特定的本地开发服务器。 Please try the following: 请尝试以下操作:

First ensure you are running the latest version of the plugin: 18.6.1 (as of this writing). 首先,请确保您正在运行插件的最新版本: 18.6.1 (在撰写本文时)。 You can verify this in the plugin manager under Settings -> Plugins -> Google Cloud Tools . 您可以在插件管理器的“ Settings -> Plugins -> Google Cloud Tools下对此进行验证。

In your src/main/webapp directory, create a WEB-INF folder if there is not one already. 在您的src/main/webapp目录中,如果尚未创建一个WEB-INF文件夹。 Inside of that folder, create a file named appengine-web.xml (the configuration file needed for App Engine standard apps). 在该文件夹内,创建一个名为appengine-web.xml的文件(App Engine标准应用程序所需的配置文件)。 Populate that file with the following starter xml: 使用以下启动器xml填充该文件:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <threadsafe>true</threadsafe>
    <runtime>java8</runtime>
</appengine-web-app>

After doing this, the plugin should detect that you are working with an App Engine standard project and pop up a Framework Support addition menu - accept the prompt. 完成此操作后,插件应检测到您正在使用App Engine标准项目,并弹出Framework Support附加菜单-接受提示。 If you don't see it, you can go to Tools -> Google Cloud Tools -> Add App Engine Support -> App Engine standard and select your module. 如果看不到它,则可以转到Tools -> Google Cloud Tools -> Add App Engine Support -> App Engine standard并选择您的模块。

After this, the local-run and deployment run configurations should be created for you allowing you to run and debug your app locally, and then deploy it to GCP App Engine. 此后,应为您创建本地运行和部署运行配置,以允许您在本地运行和调试应用程序,然后将其部署到GCP App Engine。

Note that there will be a release coming soon that will fix auto-generation of the app engine config file for Maven and Gradle projects (via the tools menu mentioned above). 请注意,即将发布的版本将修复Maven和Gradle项目的App Engine配置文件的自动生成(通过上述工具菜单)。 This would allow you to skip the manual steps. 这将允许您跳过手动步骤。 For now you should be able to do it manually as desribed above. 现在,您应该能够如上所述手动进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM