2

This is my first question on here so apologies if its not detailed enough. I am trying to set up a post-commit batch job for work that I am doing. I am using VisualSVN to manage my repository. I have the following post-commit.bat file:

REM Get the commit variables
SET REPOSITORY_PATH=%1
SET REVISION=%2
CD "C:\ProgramData\Oracle\Java\javapath"
java -jar "C:\Users\Nick\Developer\Repository\Restaurant_System\hooks\post_commit_hook.jar"

I then have the following jar file:

/**
 * 
 */
package svn.hooks;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;

/**
 * Name: post_commit_hook Purpose/Description: TODO
 */
public abstract class post_commit_hook {

    /**
     * Name: main Description: The main entry point of the program Returns: void
     */
    public static void main(String[] args) {
        try {
            System.err.println("We're In!"); //This should send a message to the client committer (but it doesn't)
            String[] command = { "CMD", "/C", "call", "C:/Scripts/svn-backup.bat"};
            ProcessBuilder probuilder = new ProcessBuilder(command);

            Map<String, String> env = probuilder.environment();
            PrintWriter writer = new PrintWriter("C:/Users/Nick/Desktop/test.txt", "UTF-8");
            writer.println(env.get("Path"));
            writer.close();

            Process process = probuilder.start();

            // I have stream readers and such here, but not to bore you with that!

            // Wait to get exit value
            int exitValue = process.waitFor();
            System.out.println("\n\nExit Value is " + exitValue);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

When I run this jar file independently on the server, it does its job correctly. Though when I perform a commit (hence triggering a post-commit event) the jar does not run. I have done the following to help work out the problem:

  1. Checked the .jar is being referenced correctly in the post-commit.bat file by changing the directory to a non-existent one (J:\Users\Nick\Devel........\post_commit_hook.jar). I get an error client side showing the following: (Warning: post-commit failed on exit code 1, unable to access jarfile)

Client-side Commit Response (Eclipse)

So this seems to indicate to me that the post-commit script is referencing the .jar file and knows what to do with it? As when it references the file correctly (C:\Users...) there's no error...

  1. I have checked that both 'VisualSVNServer Admins' and NETWORK-SERVICE have permission to execute the .jar:

.jar permissions

The permissions are in place...

  1. I am aware that there may be PATH environment issues, and so I have included code in the JAR file to print the variable... But this doesn't help if it can't even run under the VisualSVN hook!

I have spent days on this issue and am getting nowhere close to a solution, having scoured various forums and not found anything that works :(

I hope someone can help me with this!

bahrep
  • 29,961
  • 12
  • 103
  • 150
NickSellen
  • 21
  • 2
  • 1
    `java -jar "C:\Users\Nick\Developer\Repository\Restaurant_System\hooks\post_commit_hook.jar"` why don't you pass arguments at this string? It gets called without any arguments. – bahrep Oct 13 '15 at 11:36
  • My guess is that this has very little to do with `batch-file` processing. Parameters %1 and %2 should be checked for validity. – lit Oct 13 '15 at 16:07
  • Thanks for taking a look guys, unfortunately I have tried adding parameters to the .jar file in the batch but this has no effect. I don't yet utilise these parameters yet in any case, I would just like to get the server to initiate a .jar file before I do anymore useful development with it. – NickSellen Oct 13 '15 at 21:32

0 Answers0