Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing application parameters #2

Closed
PatrickHaas opened this issue Mar 1, 2016 · 13 comments
Closed

Passing application parameters #2

PatrickHaas opened this issue Mar 1, 2016 · 13 comments
Assignees

Comments

@PatrickHaas
Copy link

Hey there!
I've been trying to pass an application parameter into my application on several ways now but it kinda ends like I don't find the right way to do it.

I tried passing it via
jvmProperties=--myOption=myValue and
userJvmOptions=--myOption=myValue
also tried appending an paramfile via
-paramfile file

  • nothing happened...

Would you be so kind to help me out here?

thanks so much for this project by the way!!

best regards
patrick

@edvin
Copy link
Owner

edvin commented Mar 1, 2016

Hi Patrick,

These are not jvm parameters, so you should simply pass them as --myOption=myValue.

Also, be aware that this feature was introduced in version 1.0.7 - make sure you are using this version.

Are you running the application from an IDE or from the command line? If you're running it from the IDE, maybe you could supply me with a screenshot of the run configuration?

Also, from which method are you accessing the parameters? If you can't get it to work I would be very grateful if you can upload a sample that shows the problem and I'll investigate.

@PatrickHaas
Copy link
Author

Hey Edvin,
thanks for the fast answer!
Ok I understand. The problem for me is that I don't know where to put these parameters inside my pom file.
I did see that you pass the application parameters in your launcher to the using application with
ParametersImpl.registerParameters(app, getParameters()); is that right?

The following is my pom description part for fx launcher

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <outputDirectory>${app.dir}</outputDirectory>
            </configuration>
        </plugin>
        <!-- Copy dependencies to appdir -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <configuration>
                <excludeScope>provided</excludeScope>
                <outputDirectory>${app.dir}</outputDirectory>
                <stripVersion>true</stripVersion>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.4.0</version>
            <!-- Generate app.xml manifest -->
            <executions>
                <execution>
                    <id>create-manifest</id>
                    <phase>package</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>fxlauncher.CreateManifest</mainClass>
                        <arguments>
                            <argument>${app.url}</argument>
                            <argument>${app.mainClass}</argument>
                            <argument>${app.dir}</argument>
                        </arguments>
                    </configuration>
                </execution>
                <!-- Embed app.xml inside fxlauncher.xml so we don't need to reference 
                    app.xml to start the app -->
                <execution>
                    <id>embed-manifest-in-launcher</id>
                    <phase>package</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>jar</executable>
                        <workingDirectory>${app.dir}</workingDirectory>
                        <arguments>
                            <argument>uf</argument>
                            <argument>fxlauncher.jar</argument>
                            <argument>app.xml</argument>
                        </arguments>
                    </configuration>
                </execution>
                <!-- Create native installer. Feel free to add more arguments as needed. 
                    https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javapackager.html -->
                <execution>
                    <id>installer</id>
                    <phase>install</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>javapackager</executable>
                        <arguments>
                            <argument>-deploy</argument>
                            <argument>-native</argument>
                            <argument>-outfile</argument>
                            <argument>installer</argument>
                            <argument>-outdir</argument>
                            <argument>${app.installerdir}</argument>
                            <argument>-srcdir</argument>
                            <argument>${app.dir}</argument>
                            <argument>-srcfiles</argument>
                            <argument>fxlauncher.jar</argument>
                            <argument>-appclass</argument>
                            <argument>fxlauncher.Launcher</argument>
                            <argument>-name</argument>
                            <argument>${app.name}</argument>
                            <argument>-title</argument>
                            <argument>${app.name}</argument>
                            <argument>-vendor</argument>
                            <argument>${app.vendor}</argument>
                            <argument>-BappVersion=${app.version}</argument>
                            <argument>-BshortcutHint=${app.createDesktopShortcut}</argument>
                            <argument>-BsystemWide=false</argument>
                            <argument>-Bruntime=${app.runtime.path}</argument>
                        </arguments>
                    </configuration>
                </execution>
                <!-- Copy application artifacts to remote site using scp (optional) -->
                <execution>
                    <id>deploy-app</id>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>scp</executable>
                        <arguments>
                            <argument>-r</argument>
                            <argument>${app.dir}/.</argument>
                            <argument>${app.deploy.target}</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

So when I get you right all I need to do is putting these parameters as arguments to the configuration of the "embed-manifest-in-launcher" execution like ...

<configuration>
                            <executable>jar</executable>
                            <workingDirectory>${app.dir}</workingDirectory>
                            <arguments>
                                <argument>uf</argument>
                                <argument>fxlauncher.jar</argument>
                                <argument>app.xml</argument>
<!-- application arguments? -->
** <argument>--myOption=myValue</argument>**
                            </arguments>
                        </configuration>

?

Thanks for the version hint and yes I'm using a 1.0.7 dependency

@edvin
Copy link
Owner

edvin commented Mar 2, 2016

Ah, I see. The manifest embedding does not support hard coded parameters. You can only use parameters when you actually execute the fxlauncher.jar, like this:

java -jar fxlauncher.jar --myOption=myValue

You can however add the arguments to the native installer via the -paramfile <file> option so that they will be added when the jar is executed.

The point of parameters the way I see it, is that they should be user configurable. If you add them to the manifest, they would be hard coded, so you might as well have hard coded the result of the parameters directly in the application. There might be a use case I'm missing here, and I've found a way to support this if necessary. If you can explain the use case for this, I'll be happy to add support!

@edvin
Copy link
Owner

edvin commented Mar 2, 2016

I found a nice way to implement this, so I'll get right on it :) Parameters given in the manifest will be forwarded to the application unless they are overriden on the command line. You should add the arguments exactly as you did in the "embed-manifest-in-launcher" execution above. Hang on, will get right back to you.

@PatrickHaas
Copy link
Author

This would be very nice :) Thank you so much!

@edvin
Copy link
Owner

edvin commented Mar 2, 2016

My pleasure :) I just released version 1.0.8, it should hit Maven central within the hour. Let me know how it goes, OK?

@edvin edvin self-assigned this Mar 2, 2016
@edvin
Copy link
Owner

edvin commented Mar 2, 2016

1.0.8 is in Maven Central now :)

@PatrickHaas
Copy link
Author

My configuration now looks like:

<execution>
                        <id>embed-manifest-in-launcher</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>jar</executable>
                            <workingDirectory>${app.dir}</workingDirectory>
                            <arguments>
                                <argument>uf</argument>
                                <argument>fxlauncher.jar</argument>
                                <argument>app.xml</argument>
                                <argument>--mode=${app.mode}</argument>
                            </arguments>
                        </configuration>
                    </execution>

but I get en error while executing the install goal - something like
--mode=minimal: File not found...

any ideas?

@edvin
Copy link
Owner

edvin commented Mar 2, 2016

I think the XML tags got lost in your last post, can you try again? This should work:

<configuration>
    <mainClass>fxlauncher.CreateManifest</mainClass>
    <arguments>
        <argument>${app.url}</argument>
        <argument>${app.mainClass}</argument>
        <argument>${app.dir}</argument>
        <argument>${app.parameters}</argument>
        </arguments>
</configuration>

Where app.parameters is defined like this:

<app.parameters>--mode=minimal</app.parameters>

Can you make sure you have a similar structure? This should also work:

(last parameter in the arguments list)

<argument>--mode=${app.mode}</argument>

@edvin
Copy link
Owner

edvin commented Mar 2, 2016

Ah, you added the fourth argument to embed-manifest-in-launcher, but you should add it to create-manifest :) Sorry for that!

@edvin
Copy link
Owner

edvin commented Mar 2, 2016

(I made the same mistake in the Gradle example)

@PatrickHaas
Copy link
Author

Guess that's it! Works fine! Thank you very much for this!!

@edvin
Copy link
Owner

edvin commented Mar 2, 2016

Perfect! Thanks for making FXLauncher even better :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants