0

I want to create a method which does the following:

Creates a batch file in the current directory.

Runs the batch file (shut down hook) when the JAR is closed.

The batch file will delete the JAR file.

My problem is that I don't know how to create a batch File in Java and make sure that it deletes the current JAR file (no matter what the JAR file is renamed to).

Research:

Creating a ".bat" file, run it and delete it from Java https://coderanch.com/t/475303/java/create-execute-batch-file-java http://www.dreamincode.net/forums/topic/74058-how-to-create-batch-file-for-java-project/

I would imagine you would create the batch file, write to it and get the current JAR name and put the code for deleting it in the file - though I don't know what writing "IT" actually is.. What is the "syntax" for batch files? I'm sorry for such a stupid question.

Thank you.

Community
  • 1
  • 1
Archie
  • 51
  • 6
  • Actually, probably the easiest way to achieve what you want is to load some important classes from the server dynamically using a network classloader. That way you don't need to worry about deleting anything (this whole bat deleting jar approach is really bad) and your client will still be fairly safe from evil hackers. – Kayaman Feb 17 '17 at 21:45
  • @Kayaman can you explain what you mean? The server will send a "NoUserFound" class to the user if they are "not registered", after this I want the file to delete. Would I run something from the network that would close the JAr file and delete it? Can you explain more indepth! Thank you. – Archie Feb 17 '17 at 22:08
  • No, I mean that you'll load a significant class over the network from the server. If the user is registered, the client is allowed to load the class. If not, the class loading is prevented. This way unregistered users will never receive a part of the code that's required for running. This might be a bit advanced for you though, but it would be a nice and tight solution. Note that I'm talking about dynamic class loading here. Not just sending objects over the network. – Kayaman Feb 17 '17 at 22:11
  • @Kayaman ah that would be a good solution. How would I "disable" class loading? http://stackoverflow.com/questions/148681/unloading-classes-in-java If you can link me to any resources I would really appreciate it. – Archie Feb 17 '17 at 22:14
  • You'll want to google around for tutorials/documentation on dynamic classloading and network classloaders. You don't need to disable class loading or unload classes. – Kayaman Feb 17 '17 at 22:17
  • @Kayaman I have just looked into URLClassLoader and such - how would I get a server ClassLoader? – Archie Feb 17 '17 at 22:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/136003/discussion-between-archie-and-kayaman). – Archie Feb 17 '17 at 22:25
  • Well no, you'd use an URLClassloader to load the classes from the server, if allowed. But I guess this gets a little overly complicated, especially if you haven't worked with Java except in the confines of the minecraft plugin system. Don't have time to chat now, it's getting too late at my end of the world. – Kayaman Feb 17 '17 at 22:26
  • @Kayaman I've worked with networking before - I made a chat application for school. I prefer creating software and that is what I want to move onto. Thank you very much for your help! – Archie Feb 17 '17 at 22:33

0 Answers0