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.
Asked
Active
Viewed 58 times
1 Answers
0
Successfully accomplished that manually by doing this:
Get rid of all NetBeans' crap. Delete
nbproject/*,build.xml,manifest.mf, ...Correct
srcto includemain/java. My NetBeans projects sources were stored undersrc/package_name, while in Mavensrc/main/java/package_name.Added Maven's
POM.xmlAdded 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,293
- 1
- 17
- 36