Reputation: 761
My program only works with ip4 and gives an error with ip6 so I need to run the jar with
-Djava.net.preferIPv4Stack=true
Is there a way to write this line into pom.xml and whenever someone opens the jar that the application will try to connect IPv4?
Upvotes: 4
Views: 4328
Reputation: 45309
No, there is no way to do that at build time. The parameter is passed to the JVM when java -jar artifact.jar
is run.
Your alternative is to do that yourself in code (main method is probably the place where you can change this property the earliest possible):
public static void main(String... args) {
System.setProperty("java.net.preferIPv4Stack", "true");
}
Upvotes: 4
Reputation: 2413
You can use maven-surefire-plugin
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<systemPropertyVariables>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
More details in this link.
Upvotes: 1