1

I am generating a .jar file with a mvn clean install command. This jar file contains a sh script that is supposed to be moved to /tmp and then used to generate images from pdf files.

EDIT : The file is not really moved. It's created in my /tmp from the .jar.

The .jar file is generated from windows but used from a redhat linux production server.

Sometimes, the script won't work because its header seems incorrect in hexadecimal (using vim and typing :%!xxd).

In the correct version of my script, the first line looks like this :

0000000: 2321 2f62 696e 2f62 6173 680a 5044 4654 #!/bin/bash.PDFT

In the incorrect version, you can see this :

0000000: 2321 2f62 696e 2f62 6173 680d 0a50 4446 #!/bin/bash..PDF

And without hexadecimal, the beginning of the file looks like this (obvisously) :

#!/bin/bash
PDFTOPPM=pdftoppm
CONVERT=convert
LOG=/tmp/pdf2imgSh.log

Has anyone ever encountered this problem ? How can I force my maven install (on windows) to correctly generate the jar without broken header in scripts ?

The problem is a bit obscure to me, so don't hesitate to ask for edits or precisions.

Thanks in advance.

DamienB
  • 419
  • 1
  • 6
  • 20
matthieusb
  • 505
  • 1
  • 10
  • 34
  • It is an encoding issue. How exactly do you generate the file? What plugin/code do you use? – vempo Jun 16 '17 at 09:51
  • As you say `sometimes`. If you are using Git on Windows have a look at the config settings [core.safecrlf](https://git-scm.com/docs/git-config#git-config-coresafecrlf) and [core.autocrlf](https://git-scm.com/docs/git-config#git-config-coreautocrlf). – SubOptimal Jun 16 '17 at 09:51

2 Answers2

4

Following @h22 answer and @SubOtpimal comment, I think you can force maven to encode a specific file's EOL.

Add this plugin to your pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>ant-test</id>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <fixcrlf srcdir="${basedir}/src/main/resources/yourfilepath" eol="unix" />
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Change the path with your own file or folder. It works recursively. Be careful not to forget the path, or it will break your jars. This might do the trick. Hope this helps !

e.martinez
  • 56
  • 3
1

The versions differ by the line endings (Windows version and Linux version). The code which generates the script uses platform specific end of line terminators (0A vs 0D 0A).

You can change the end of line separator without altering the code. Set default end of line terminator as discussed here. Configuring system properties may work, otherwise you may need to edit the mvn script.

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93