1

I'm currently writing on a tool that is client server based. Because of unstable IP-Adresses, my idea is to let the server-Application compile a client-application with the right IP of the server.

Step-by-step:

  1. The serverapplication starts.
  2. The user looks, what current IP his server-computer has (this can be done manually over a webbrowser).
  3. With this IP he creates (compiles) a client which search a connection to this IP (once started).
  4. To make this possible, it's necessary to compile the client, after the IP has been set.
  5. The client runs as background application without any GUI or console-window. So adding the IP on the client side isn't what I search for. The biggest newbies should be able to just run the client and their work ist done.

I tought that I could just unpack javac (out of the Java-application), then write the class to a file (as complete string) and then run a console command, which uses the javac.exe to compile a runnable jar file. But of course it isn't that easy. My problem is that I don't want to put the whole JDK-Folder to the server-application, just to compile the client. Does anyone of you know a proper way how I could handle this?

Important is, that I have to fight with computers, which haven't a JDK installed, just the standard JRE which hasn't a compiler on board (of course).

codepleb
  • 10,086
  • 14
  • 69
  • 111
  • If server and client are running on the same local network you could also do something like: http://stackoverflow.com/questions/6935212/how-to-publish-file-server-service-to-local-network – zapl Mar 15 '14 at 00:16

1 Answers1

2

That is definitely not a good way of going about this. There are a couple of alternative approaches which would be much simpler:

  1. Pass the IP address or hostname of the server to the client application as a parameter (e.g, via the command line). This requires no changes to the client at all, but will require you to have some way of passing that parameter on.

  2. If you want to get really clever, you could potentially make the filename of the client application contain the IP (e.g, as a hexadecimal value: a client that connected to 127.0.0.1 might be called client-7f000001.jar). You'd have to make sure it didn't get renamed, though.

  3. Embed a text file containing the IP address of the server in the client JAR file. Since a JAR is just a ZIP archive, you don't need a compiler to do this.

  • To your 1st point: How can I pass the IP, when there is no connection? The IP is the basic of all further communication, but without it, the clients doesn't even know where they have to "listen". Or did I get something wrong? 3rd: This would actually work... the more I think about it, the more sympathic is sounds. Then I could just edit this textfile and "unpack" the compiled client. I think this is a good alternative. But a question: Is it that hard to compile something like this or is it just a bit overhead? Thanks for your help! :) – codepleb Mar 15 '14 at 16:37
  • @TrudleR as hard as .zipping any files. (=not hard at all by any means) – eis Mar 15 '14 at 16:56
  • @TrudleR but if you intended to compile the client jar, you have to have some means of delivering that client jar to target computer -> you have to have some mechanism of delivering stuff that you can equally well use to pass the IP as textual information and use it when you start the application. I don't see any reason of having the IP stored within the .jar. – eis Mar 15 '14 at 17:01
  • It's cleaner, if you store it in the jar. :) You just have to hand over one file and it can totally handle itself. Maybe I'm a bit usability-friendly at this point, but I hate having multiple puzzle parts for just one program. Anyway: If it's IN the jar, you don't have to worry about the path where the textfile can be found. It's always an internal path and always the same. – codepleb Mar 15 '14 at 17:22