1

I have a couple of mature projects developed in NetBeans. I want to stop using NetBeans and migrate into a Java CI with Maven in GitHub, so that every time a commit is pushed, a JAR file is created in GitHub. I would also like to keep history in git.

Raf
  • 1,628
  • 3
  • 21
  • 40

1 Answers1

1

Successfully accomplished that manually by doing this:

  1. Get rid of all NetBeans' crap. Delete nbproject/*, build.xml, manifest.mf, ...

  2. Correct src to include main/java. My NetBeans projects sources were stored under src/package_name, while in Maven src/main/java/package_name.

  3. Added Maven's POM.xml

  4. Added GitHub's workflow file .github/workflows/maven.yml, including path to main class to make the JAR file runnable as per this answer

Commit and push those changes into GitHub and your JAR file will be magically created under Actions.


File .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

File pom.xml (edit to fit your project)

<?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>
Raf
  • 1,628
  • 3
  • 21
  • 40
  • I really detest how much rubbish NetBeans creates. Trying to do the same with `ant` and facing a lot of problems. I feel this IDE is a bit too intrusive... – Rafs Oct 26 '22 at 12:26
  • Interesting start for my nbproject. Thanks :) Did you manage to automatically transform all the dependencies from the ext folder into maven dependencies? – adranale Jan 20 '23 at 19:32
  • And my project is a web project that is deployed on tomcat using nbproject/ant-deploy.xml. Did you manage to automatically transform this deploy task as a GitHub action? – adranale Jan 20 '23 at 19:33
  • @adranale my project did not have dependencies so can't say anything about that – Raf Jan 22 '23 at 09:56