天天看點

idea 建立項目的完整流程

1,idae建立maven項目

https://blog.csdn.net/qq_37952161/article/details/80293507

2,IDEA右鍵建立時沒有Java Class選項

https://www.cnblogs.com/zimo-jing/p/9628784.html

3.maven在打包的時候會碰到一些問題,

 3.1 注意每次打包的時候編譯一遍,執行下代碼。

 3.2 需要添加的pom中

   注意 jar 包,注意main,注意私有服務

<?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>com.java.senddata</groupId>
  <artifactId>SendData</artifactId>
  <version>1.0-SNAPSHOT</version>
//注意修改
  <packaging>jar</packaging>

  <name>SendData Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
  <repositories>
    <repository>
      <id>nexus-scistor</id>
      <name>nexus-scistor</name>
      <url>http://192.168.31.193:8088/repository/maven-central/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </repository>

    <repository>
      <id>aliyun</id>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>

    <repository>
      <id>mvnrepository</id>
      <url>http://mvnrepository.com/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.avro</groupId>
      <artifactId>avro</artifactId>
      <version>1.8.2</version>
    </dependency>
    <dependency>
      <groupId>com.twitter</groupId>
      <artifactId>bijection-core_2.11</artifactId>
      <version>0.9.6</version>
    </dependency>
    <dependency>
      <groupId>com.twitter</groupId>
      <artifactId>bijection-avro_2.11</artifactId>
      <version>0.9.6</version>
    </dependency>
    <dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.1.1</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>SendData</finalName> 
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                  </excludes>
                </filter>
              </filters>
              <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
              <transformers>
                <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.Run</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin> 
      </plugins>
  </build>
</project>
      

idea jar包,

idea 建立項目的完整流程

Linux上輸出日志:

1,打好jar包後,再Linux上執行,指令如下:

nohup java -jar BiuBiuBiu.jar >output 2>&1 &

2.當從idea上通過maven 打好jar包後,通過nohup 執行的時候,請注意。output 就是你執行的日志所在檔案

3.通過tailf -n 100 進行檢視。

4,如果想輸出日志,直接通再idea上System.out.println("") 即可。

5.如果 需要 java -jar 傳參數。需要再執行的旁邊添加參數。

idea 建立項目的完整流程

6。打jar包的時候不要忘記編譯一遍,執行下代碼即可。