天天看点

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包的时候不要忘记编译一遍,执行下代码即可。