【问题标题】:How to migrate from a NetBeans project into Java CI with Maven in GitHub?如何使用 GitHub 中的 Maven 从 NetBeans 项目迁移到 Java CI?
【发布时间】:2020-10-18 18:43:54
【问题描述】:

我有几个使用 NetBeans 开发的成熟项目。我想停止使用 NetBeans 并在 GitHub 中使用 Maven 迁移到 Java CI,这样每次推送提交时,都会在 GitHub 中创建一个 JAR 文件。我也想在 git 中保存历史记录。

【问题讨论】:

    标签: maven github-actions


    【解决方案1】:

    通过这样做手动成功地完成了:

    1. 摆脱所有 NetBeans 的垃圾。删除nbproject/*build.xmlmanifest.mf、...

    2. 更正src 以包括main/java。我的 NetBeans 项目源存储在 src/package_name 下,而在 Maven 中 src/main/java/package_name

    3. 添加了 Maven 的POM.xml

    4. 添加了 GitHub 的工作流文件 .github/workflows/maven.yml,包括主类的路径,以使 JAR 文件可以按照 this answer 运行

    提交这些更改并将其推送到 GitHub,您的 JAR 文件将在 Actions 下神奇地创建。


    文件.github/workflow/maven.yml

    # This workflow will build a Java project with Maven
    # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
    
    name: Java CI with Maven
    
    on:
      push:
        branches: [ master ]
      pull_request:
        branches: [ master ]
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v2
        - name: Set up JDK 1.8
          uses: actions/setup-java@v1
          with:
            java-version: 1.8
        - name: Build with Maven
          run: mvn -B package --file pom.xml
        - run: mkdir staging && cp target/*.jar staging
        - uses: actions/upload-artifact@v1
          with:
            name: Package
            path: staging
    

    文件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>your_id</groupId>
        <artifactId>your_artifact_id</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
        <build>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <configuration>
                <archive>
                  <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>fully.qualified.MainClass</mainClass>
                  </manifest>
                </archive>
              </configuration>
            </plugin>
          </plugins>
        </build>
    </project>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-13
      • 2020-09-29
      • 1970-01-01
      • 2010-10-15
      • 2021-11-21
      • 1970-01-01
      • 2015-09-21
      • 2016-01-30
      相关资源
      最近更新 更多