Intellij管理maven项目

来自ling
跳转至: 导航搜索

调试

  • @ActiveProfiles(ProfilesDef.DEV) 必须在基类和@ContextHierarchy等在一起DataSource dataSource才有效,否则DataSource dataSource会找不到
  • 如果各种代码修改后无效,试试 maven -clean install
  • 更改好代码后需要手工编译代码,全部编译ctrl+f9,当前文件ctrl+shift+f9
  • 或者设置Compiler=>make project automatically
    • 如果tomcat 打开右上角的Edit Configuration进入Tomcat配置选项页面 部署方式选择 explode 将On frame deactivation选项更改为 Update classes and resources
    • 如果jetty 打开右上角的Edit Configuration进入Tomcat配置选项页面 部署方式选择 explode 将On frame deactivation选项更改为 Update classes and resources
Intellij tomcat debug.PNG
  • 经测试,修改config文件和java文件,调试都能立即生效
  • spring cloud config jvm
--spring.profiles.active=dev --spring.cloud.config.uri=http://localhost:7001/
Intellij.springcloud.config.clent.jvm.PNG

导入已有maven项目

  • Intellij maven import.PNG
  • Intellij maven import window.PNG

创建子模块

  • 开始创建子模块. File -> New -> Module -> Maven
  • Intellij maven newchild.PNG
  • Intellij maven newchild1.PNG

maven jetty

  • 第一步,添加pom.xml,其中,finalName 为项目名字
  • <build>
            <finalName>ideasimple</finalName> <plugins>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>7.1.6.v20100715</version>
                    <configuration>
                        <stopPort>9988</stopPort>
                        <stopKey>foo</stopKey>
                        <scanIntervalSeconds>5</scanIntervalSeconds>
                        <connectors>
                            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                <port>8080</port>
                                <maxIdleTime>60000</maxIdleTime>
                            </connector>
                        </connectors>
                        <webAppConfig>
                            <contextPath>/</contextPath>
                        </webAppConfig>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.4.2</version>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <webResources>
                            <resource>
                                <!-- 元配置文件的目录,相对于pom.xml文件的路径 -->
                                <directory>src/main/webapp/WEB-INF</directory>
                                <!-- 是否过滤文件,也就是是否启动auto-config的功能 -->
                                <filtering>true</filtering>
                                <!-- 目标路径 -->
                                <targetPath>WEB-INF</targetPath>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.7
                   <target>1.7</target>
                   <encoding>UTF-8</encoding>
               </configuration>
           </plugin>
       </plugins>
   </build>

</source>

  • 第二步,运行:

Intellij maven jetty1.png

Intellij maven jetty2.png

使IntelliJ IDEA智能提示忽略大小写

  • 打开设置(CTRL+ALT+S)搜索editor,找到“Code Completion”->点击Case sensitive completion后面的选择框,选中None,然后一路确定即可。

jetty配置备份

  • 跨项目后无法热代码调试,没找到解决防范,所以改为ide自带的调试工具,并且从框架中去除了maven jetty调试方式
        <jettyVersion>9.2.8.v20150217</jettyVersion>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>${jettyVersion}</version>
        </dependency>

<plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jettyVersion}</version>
                <configuration>
                    <httpConnector>
                        <port>7180</port>
                    </httpConnector>
                    <stopKey>shutdown</stopKey>
                    <stopPort>9966</stopPort>
                    <scanIntervalSeconds>1</scanIntervalSeconds><!--更改后能立即生效-->
                    <reload>manual</reload>
                    <dumpOnStart>true</dumpOnStart>
                    <webApp>
                        <contextPath>/</contextPath>
                        <!--
                        <resourceBases>
                          <resourceBase>${project.basedir}/src/main/webapp</resourceBase>
                          <resourceBase>${project.basedir}/commons</resourceBase>
                        </resourceBases>
                        -->
                    </webApp>
                    <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
                        <filename>target/access-yyyy_mm_dd.log</filename>
                        <filenameDateFormat>yyyy_MM_dd</filenameDateFormat>
                        <logDateFormat>yyyy-MM-dd HH:mm:ss</logDateFormat>
                        <logTimeZone>GMT+8:00</logTimeZone>
                        <append>true</append>
                        <logServer>true</logServer>
                        <retainDays>120</retainDays>
                        <logCookies>true</logCookies>
                    </requestLog>
                </configuration>
            </plugin>
        </plugins>

新窗口打开项目

Intellij.openproject.newwindow.PNG

DskipTests

-DskipTests.PNG