0

I try to achieve something that I imagined very simple, but which is finally harder than expected.

I have a folder : source/. I have a second one : target/. I create a file test.jar in my first folder. Then, I want this file to appear and be executable in my second folder. I see 3 options :

  • manually copy/paste my file. It works but... I don't want to do it each time I update my file.

  • symbolic link. It works, but if I execute the jar file, the context is source/ and not target/ like I would like.

  • hard link. That's exactly what I need, but the issue is that test.jar is not modified, but generated. This means that after erasing source/test.jar, target.test.jar still references the old file... Is it possible to force the 2 files to have always the same value ?

Thanks for your help !

EDIT : For now, I solved the problem by adding a line to copy my file from source/ to target/ inside a script that I will execute anyway after generating the jar. I think that what I wanted to do is actually impossible. It would need a new kind of linking which links the content of 2 files given their pathname and not their inode...

Sharcoux
  • 5,546
  • 7
  • 45
  • 78
  • Depending on your environment, you can setup a build task that copies the (generated?) `.jar` for you. It will increase portability, since Windows doesn't support symlinks like Unix does. – rr- Oct 17 '14 at 10:55
  • >>"I don't want to do it each time I update my file." Check if [`inotifywait`](http://man.cx/inotifywait) or [`rsync`](http://man.cx/rsync) can help you. – anishsane Oct 17 '14 at 11:18
  • I checked inotifywait and rsync. I'm sorry, I don't see exactly how I should use it to solve my problem. I think that the comment of @rr suggests the best approach for my case. I'm using Maven2. I will try, but I don't know yet how to achieve this. I will make some research and come back. – Sharcoux Oct 18 '14 at 18:51
  • Ok. As I need this only for myself, I don't want to modify the pom. Is there a way with Maven to execute a build task only on my computer ? – Sharcoux Oct 20 '14 at 07:46

2 Answers2

0

Don't create a soft link of the file. Create a soft link of the entire folder.

Something like

ln -s {whatever path}/source/ {whatever path}/target

Then the folder target/ is a folder-link to the first folder and context should be the same.

You can also try using git (locally) and checkout source/ to folder target.

sestus
  • 1,875
  • 2
  • 16
  • 16
0

You can try creating an executable shell script named test.jar in the target directory and make it call the path/source/test.jar passing forwarding all the parameters. Something like:

#!/bin/bash
path/source/test.jar "$@"
jmajnert
  • 418
  • 4
  • 8
  • Thanks for your help. It could be a good idea, but I'd rather the jar file to be physically present in the folder. This way, if I want to copy, move, compress... the whole folder, I can do it very easily. – Sharcoux Oct 24 '14 at 06:39
  • Then I guess you need to have a hard copy in the directory and make sure updates to source/test.jar are reflected in target dir... modifying the build procedure to ensure this is your best choice then – jmajnert Oct 24 '14 at 07:46