Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Last active January 22, 2019 02:54
Show Gist options
  • Save dmikurube/f78abd53189af261d09d080f0ad1f611 to your computer and use it in GitHub Desktop.
Save dmikurube/f78abd53189af261d09d080f0ad1f611 to your computer and use it in GitHub Desktop.
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.+'
}
sourceSets {
main {
java {
srcDir '.'
}
}
}
test {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
}
}
jar {
manifest {
attributes 'Main-Class': 'Selfupdate'
}
}
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Selfupdate {
public static void main(final String[] args) throws URISyntaxException, IOException {
final URI uri = Selfupdate.class.getProtectionDomain().getCodeSource().getLocation().toURI();
final Path oldPath = Paths.get(uri);
final Path newPath = oldPath.resolveSibling(oldPath.getFileName().toString() + ".renamed");
Files.move(oldPath, newPath);
/*
final File oldFile = new File(uri);
final File newFile = new File(Paths.get(uri).toString() + ".renamed");
oldFile.renameTo(newFile);
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment