Last active
January 22, 2019 02:54
-
-
Save dmikurube/f78abd53189af261d09d080f0ad1f611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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