Skip to content

wilbert-vb/tmc-netbeans

 
 

Repository files navigation

Complete Guide: Building TMC-NetBeans Plugin for Apache NetBeans

This guide provides step-by-step instructions for building the Test My Code (TMC) NetBeans plugin from source, including all necessary dependencies and corrections for compatibility with modern Java versions.

Prerequisites

  • Java 8 JDK (required for building - some components don't work with newer Java)
  • Maven 3.x
  • NetBeans 27 (or your target NetBeans version)
  • Git

Important Notes

  1. Use Java 8 for building - The TMC projects were designed for Java 8. While you can run NetBeans with Java 21, build the dependencies with Java 8.
  2. Maven HTTP Blocker - Maven 3.8.1+ blocks HTTP repositories by default. The TMC Maven repository is down, so all dependencies must be built from source.
  3. Version Compatibility - You'll need to adjust dependency versions in pom.xml files to match what you actually build.

Step 1: Set Up Java 8 Environment

# Install Java 8
sudo apt install openjdk-8-jdk

# Set Java 8 as active for this session
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

# Verify
java -version
javac -version

Step 2: Configure Maven

Remove or disable the HTTP blocker by deleting your Maven settings file:

# Backup existing settings
mv ~/.m2/settings.xml ~/.m2/settings.xml.backup

# Or delete it
rm ~/.m2/settings.xml

Step 3: Clone All Required Repositories

# Create a working directory
mkdir ~/tmc-build
cd ~/tmc-build

# Clone all dependencies
git clone https://github.com/testmycode/tmc-checkstyle-runner.git
git clone https://github.com/testmycode/tmc-junit-runner.git
git clone https://github.com/testmycode/tmc-langs-abstraction.git
git clone https://github.com/testmycode/tmc-langs.git
git clone https://github.com/testmycode/tmc-core.git
git clone https://github.com/testmycode/tmc-netbeans.git

Step 4: Build Dependencies in Order

4.1 Build tmc-junit-runner

cd tmc-junit-runner

# Fix Java version compatibility
sed -i 's/1\.7/1.8/g' pom.xml

# Build and install
mvn clean install -DskipTests

cd ..

4.2 Build tmc-checkstyle-runner

cd tmc-checkstyle-runner

# Fix Java version compatibility
sed -i 's/1\.6/1.8/g' pom.xml

# Build and install
mvn clean install -DskipTests

cd ..

4.3 Build tmc-langs-abstraction

cd tmc-langs-abstraction

# Build and install
mvn clean install -DskipTests

cd ..

4.4 Build tmc-langs

cd tmc-langs

# Skip checkstyle (build-tools dependency issue)
mvn clean install -DskipTests -Dcheckstyle.skip=true

# Note the version that was built
ls ~/.m2/repository/fi/helsinki/cs/tmc/tmc-langs-util/

cd ..

4.5 Build tmc-core

IMPORTANT: tmc-core's pom.xml needs version adjustments to match what you actually built.

cd tmc-core

# Check what versions you have in local repository
ls ~/.m2/repository/fi/helsinki/cs/tmc/tmc-langs-util/
ls ~/.m2/repository/fi/helsinki/cs/tmc/tmc-checkstyle-runner/

# Update dependency versions in pom.xml to match
# Example: if tmc-langs-util built as 0.7.1-SNAPSHOT instead of 0.7.16-SNAPSHOT
sed -i 's/0.7.16-SNAPSHOT/0.7.1-SNAPSHOT/g' pom.xml

# Example: if tmc-checkstyle-runner built as 3.0.3-SNAPSHOT instead of 3.0.1
sed -i 's/3.0.1/3.0.3-SNAPSHOT/g' pom.xml

# Verify the changes
grep -A 2 "tmc-langs-util" pom.xml
grep -A 2 "tmc-checkstyle-runner" pom.xml

# Build and install
mvn clean install -DskipTests

cd ..

Step 5: Build TMC-NetBeans Plugin

The tmc-netbeans project is NOT a Maven project - it's a NetBeans Ant-based project that must be built within NetBeans IDE.

5.1 Prepare NetBeans 27

  1. Open NetBeans 27

  2. Activate "Developing NetBeans" plugin:

    • Go to Tools → Plugins → Installed
    • Check the box next to "Developing NetBeans"
    • Click Activate
    • Restart NetBeans
  3. Set up NetBeans Platform (if required):

    • Download NetBeans 11.2 "OS Independent Zip"
    • Extract it somewhere
    • In NetBeans 27: Tools → NetBeans Platforms
    • Click Add Platform
    • Select the extracted NetBeans 11.2 directory

5.2 Fix NetBeans 27 Compatibility Issue

The plugin has a version check that fails with NetBeans 27. Fix it before building:

cd tmc-netbeans

# Edit the problematic file
nano ./tmc-plugin/src/fi/helsinki/cs/tmc/actions/CheckForOutdatedNetbeans.java

Find the run() method (around line 20-25) and replace it with:

@Override
public void run() {
    try {
        String version = System.getProperty("netbeans.productversion");
        if (version == null || version.length() < 4) {
            return; // Skip check for newer NetBeans versions
        }
        version = version.substring(0, 4);
        // rest of existing code...
    } catch (Exception e) {
        // Ignore version check errors for newer NetBeans
        return;
    }
}

Or simply disable the check entirely by replacing the method body with just return;

5.3 Build the Plugin in NetBeans

  1. Open the project:

    • In NetBeans 27: File → Open Project
    • Navigate to tmc-netbeans directory
    • Select it and click Open Project
  2. Build the project:

    • Right-click the project → Clean and Build
    • Wait for build to complete
  3. Create NBM files:

    • Right-click the project → Create NBMs
  4. Find the NBM files:

    cd ~/tmc-build/tmc-netbeans
    find . -name "*.nbm" -type f

    You should find:

    • fi-helsinki-cs-tmc.nbm (main plugin)
    • maven-wrapper-*.nbm (dependency)

Step 6: Install the Plugin

6.1 Save NBM Files for Future Use

# Create storage directory
mkdir ~/tmc-netbeans-nbm-files

# Copy NBM files
cd ~/tmc-build/tmc-netbeans
find . -name "*.nbm" -type f -exec cp {} ~/tmc-netbeans-nbm-files/ \;

# Verify
ls -lh ~/tmc-netbeans-nbm-files/

6.2 Install in NetBeans 27

  1. Open NetBeans 27

  2. Go to Tools → Plugins

  3. Click the "Downloaded" tab

  4. Click "Add Plugins..." button

  5. Select BOTH NBM files:

    • fi-helsinki-cs-tmc.nbm
    • maven-wrapper-*.nbm
  6. Click "Install"

  7. Accept any warnings about unsigned plugins

  8. Restart NetBeans when prompted

  9. Verify installation:

    • The TMC menu should appear in the Tools menu

Step 7: Package for Distribution

cd ~
tar -czf tmc-netbeans-plugin.tar.gz tmc-netbeans-nbm-files/

# Or create a zip
zip -r tmc-netbeans-plugin.zip tmc-netbeans-nbm-files/

Installation on Other Computers

Copy the NBM files to other machines and:

  1. Open NetBeans 27
  2. Tools → Plugins → Downloaded → Add Plugins...
  3. Select both NBM files
  4. Click Install
  5. Restart NetBeans

Troubleshooting

Common Issues and Solutions

Issue: Source option 6/7 is no longer supported

  • Solution: Update pom.xml to use Java 8: sed -i 's/1\.[67]/1.8/g' pom.xml

Issue: Could not find artifact com.sun:tools:jar

  • Solution: Use Java 8 for building (tools.jar was removed in Java 9+)

Issue: HTTP blocker preventing dependency resolution

  • Solution: Delete ~/.m2/settings.xml and clear cache:
    rm -rf ~/.m2/repository/fi/
    find ~/.m2/repository -name "*.lastUpdated" -type f -delete

Issue: Version mismatch errors during tmc-core build

  • Solution: Check what versions were actually built and update pom.xml accordingly

Issue: StringIndexOutOfBoundsException on NetBeans startup

  • Solution: Fix the CheckForOutdatedNetbeans.java file as described in Step 5.2

Summary of Key Version Adjustments

When building tmc-core, you'll likely need to adjust these dependencies:

Dependency Expected Version Likely Built Version How to Fix
tmc-langs-util 0.7.16-SNAPSHOT 0.7.1-SNAPSHOT sed -i 's/0.7.16-SNAPSHOT/0.7.1-SNAPSHOT/g' pom.xml
tmc-checkstyle-runner 3.0.1 3.0.3-SNAPSHOT sed -i 's/3.0.1/3.0.3-SNAPSHOT/g' pom.xml

Always verify what versions are in ~/.m2/repository/fi/helsinki/cs/tmc/ and adjust accordingly.

Notes

  • The entire build process takes approximately 30-60 minutes depending on your system
  • Keep the NBM files backed up - rebuilding is time-consuming
  • The plugin was originally designed for NetBeans 11.x, so some compatibility fixes are necessary for NetBeans 27
  • All dependencies must be built with Java 8 due to old API usage (tools.jar, etc.)

About

Test My Code NetBeans plugin

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 98.2%
  • C 1.3%
  • Other 0.5%