josephino
josephino

Reputation: 360

Java -XstartOnFirstThread command line options unrecognized in Linux but working in OSX

I'm using -XstartOnFirstThread argument to solve SWT launch problem in OS X in a Unit test:

    <build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-surefire-plugin</artifactId>
            <version>1.0.0</version>
            <configuration>
                <argLine>-XstartOnFirstThread</argLine>
            </configuration>
        </plugin>
    </plugins>
</build>

Test pass in OSX but fails in Linux with mentioning that -XstartOnFirstThread is Unrecognized:

[/var/local/devtools/jdk1.8.0_141/jre/bin/java, -Dosgi.noShutdown=false, 
-Dosgi.os=linux, -Dosgi.ws=gtk, -Dosgi.arch=x86_64, -XstartOnFirstThread,
-Dosgi.clean=true, -jar ...

21:22:35 [artifact:mvn] Unrecognized option: -XstartOnFirstThread
21:22:35 [artifact:mvn] Error: Could not create the Java Virtual Machine.
21:22:35 [artifact:mvn] Error: A fatal exception has occurred. Program will exit.

Is there any way to get this working on Linux, or a way to add a condition in tycho to ignore this argument in Linux.

Upvotes: 1

Views: 2911

Answers (2)

josephino
josephino

Reputation: 360

As -XstartOnFirstThread option is Mac OS X specific, using a profile that get triggered only if JUnit test is run in macOS, sounds the best option.

<profiles>
    <profile>
        <id>platform-mac</id>
        <activation>
            <os>
                <family>mac</family>
            </os>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.tycho</groupId>
                    <artifactId>tycho-surefire-plugin</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <argLine>-XstartOnFirstThread</argLine>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Upvotes: 2

GhostCat
GhostCat

Reputation: 140553

There is a misconception on your end. When you run java -X, you get told:

The -X options are non-standard and subject to change without notice.

In other words: anything that starts with -X is highly implementation specific. And of course, that adds the moment of versioning as well.

Meaning: unless you are using the exact same version of Oracle Java on Linux and on Mac, chances are that anything starting with -X might not work the same way.

In other words: most likely your expectation that this works on both platforms is flawed to begin with.

Upvotes: 1

Related Questions