0

I have a java web application project. I am using the exec-maven-plugin to execute a shell script which creates a small txt file in a directory when the project is built using mvn clean isntall. I have confirmed that the script is being executed when running mvn clean install by writing test text. However, the script is not creating the txt file.

When the script is run normally through the terminal, ie ./script.sh , the txt file is created correctly.

toTxt="hello"
printf $toTxt > testText.txt
echo 'This shows up, but testText is not created.'

Does anyone know the reason why this is happpening?

user1576752
  • 29
  • 1
  • 3
  • 10
  • What is the purpose of the text file? Why do you need it ? – khmarbaise Oct 30 '15 at 20:09
  • Pulling some basic string data from a remote server that is constantly being changed. The point is that this automates the task of having to manually update the text. Terminal commands are required thus the shell script. – user1576752 Oct 30 '15 at 20:19
  • Why do you need to pull information from a server for building ? – khmarbaise Oct 31 '15 at 12:27

2 Answers2

0

Try either echoing pwd command to see where it should create the file or add <workingDirectory>${project.build.outputDirectory}</workingDirectory> to your configuration block in pom.xml NOTE: You can specify something other than ${project.build.outputDirectory} to specifically point to the right place. And make sure you have write permissions to it.

Alex Khvatov
  • 1,415
  • 3
  • 14
  • 23
0

Keep in mind that some commands are not really external programs, but shell built-ins. This means that they don't launch programs, and maven-exec-plugin will not be able to run them. However, you can run bash to get the result, just not pwd.

bash -c "echo $(pwd)"

should do the trick. Maven is launching bash which is then running the script echo $(pwd) which calls the bash builtin function pwd and passes the result back (due to the echo).

Yes, it's a lot of work to get around the lack of a pwd program, but that's because there really isn't a pwd program, it's part of the internal offerings of bash.

http://www.tldp.org/LDP/abs/html/internal.html lists the bash internals (builtin commands).

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138