How to change some java variables before deploying on a remote server?












1















I am currently building a java web application (with netbeans).
I use Jenkins to create a release version with the following pipeline (for Jenkins):



Build -> Test -> Deploy (to a remote test webserver)



Build and Test are OK but I have a question about the deploy job.
The deploy job is currently taking my previously generated .war file and simply transfer it to a remote web server (with the "Deploy to container" plugin).
But I would like to change the database parameters of my web application first ! (in order to use another remote test database).
I would be glad to modify the java file with shell command but I can't because my .war is only composed of the compiled .class java.



So how could I change some of my web application java code (for database credentials) from the .war file before deploying it to the remote web server ?










share|improve this question


















  • 3





    You should not put configuration data in code in the first place. Move the credentials to a property file, and read that file to obtain the credentials. Then the property file can be edited after deployment in different environments. This also avoids other security concerns such as credentials being visible in your SCS, and developers needing to know Production passwords. But that is only an initial step to resolve your immediate problem, and there are multiple solutions. See How should an application store its credentials for more ideas.

    – skomisa
    Jan 2 at 8:37











  • Although you have framed your question very specifically in terms of Java, since the larger issue is how to deploy application code to different environments, I'm not sure that it really belongs on SO. You might try the Information Security site instead. Your question is also inviting opinions, which could make it off topic here.

    – skomisa
    Jan 2 at 8:42


















1















I am currently building a java web application (with netbeans).
I use Jenkins to create a release version with the following pipeline (for Jenkins):



Build -> Test -> Deploy (to a remote test webserver)



Build and Test are OK but I have a question about the deploy job.
The deploy job is currently taking my previously generated .war file and simply transfer it to a remote web server (with the "Deploy to container" plugin).
But I would like to change the database parameters of my web application first ! (in order to use another remote test database).
I would be glad to modify the java file with shell command but I can't because my .war is only composed of the compiled .class java.



So how could I change some of my web application java code (for database credentials) from the .war file before deploying it to the remote web server ?










share|improve this question


















  • 3





    You should not put configuration data in code in the first place. Move the credentials to a property file, and read that file to obtain the credentials. Then the property file can be edited after deployment in different environments. This also avoids other security concerns such as credentials being visible in your SCS, and developers needing to know Production passwords. But that is only an initial step to resolve your immediate problem, and there are multiple solutions. See How should an application store its credentials for more ideas.

    – skomisa
    Jan 2 at 8:37











  • Although you have framed your question very specifically in terms of Java, since the larger issue is how to deploy application code to different environments, I'm not sure that it really belongs on SO. You might try the Information Security site instead. Your question is also inviting opinions, which could make it off topic here.

    – skomisa
    Jan 2 at 8:42
















1












1








1








I am currently building a java web application (with netbeans).
I use Jenkins to create a release version with the following pipeline (for Jenkins):



Build -> Test -> Deploy (to a remote test webserver)



Build and Test are OK but I have a question about the deploy job.
The deploy job is currently taking my previously generated .war file and simply transfer it to a remote web server (with the "Deploy to container" plugin).
But I would like to change the database parameters of my web application first ! (in order to use another remote test database).
I would be glad to modify the java file with shell command but I can't because my .war is only composed of the compiled .class java.



So how could I change some of my web application java code (for database credentials) from the .war file before deploying it to the remote web server ?










share|improve this question














I am currently building a java web application (with netbeans).
I use Jenkins to create a release version with the following pipeline (for Jenkins):



Build -> Test -> Deploy (to a remote test webserver)



Build and Test are OK but I have a question about the deploy job.
The deploy job is currently taking my previously generated .war file and simply transfer it to a remote web server (with the "Deploy to container" plugin).
But I would like to change the database parameters of my web application first ! (in order to use another remote test database).
I would be glad to modify the java file with shell command but I can't because my .war is only composed of the compiled .class java.



So how could I change some of my web application java code (for database credentials) from the .war file before deploying it to the remote web server ?







maven tomcat jenkins java-ee netbeans






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 23:17









John DoeJohn Doe

386




386








  • 3





    You should not put configuration data in code in the first place. Move the credentials to a property file, and read that file to obtain the credentials. Then the property file can be edited after deployment in different environments. This also avoids other security concerns such as credentials being visible in your SCS, and developers needing to know Production passwords. But that is only an initial step to resolve your immediate problem, and there are multiple solutions. See How should an application store its credentials for more ideas.

    – skomisa
    Jan 2 at 8:37











  • Although you have framed your question very specifically in terms of Java, since the larger issue is how to deploy application code to different environments, I'm not sure that it really belongs on SO. You might try the Information Security site instead. Your question is also inviting opinions, which could make it off topic here.

    – skomisa
    Jan 2 at 8:42
















  • 3





    You should not put configuration data in code in the first place. Move the credentials to a property file, and read that file to obtain the credentials. Then the property file can be edited after deployment in different environments. This also avoids other security concerns such as credentials being visible in your SCS, and developers needing to know Production passwords. But that is only an initial step to resolve your immediate problem, and there are multiple solutions. See How should an application store its credentials for more ideas.

    – skomisa
    Jan 2 at 8:37











  • Although you have framed your question very specifically in terms of Java, since the larger issue is how to deploy application code to different environments, I'm not sure that it really belongs on SO. You might try the Information Security site instead. Your question is also inviting opinions, which could make it off topic here.

    – skomisa
    Jan 2 at 8:42










3




3





You should not put configuration data in code in the first place. Move the credentials to a property file, and read that file to obtain the credentials. Then the property file can be edited after deployment in different environments. This also avoids other security concerns such as credentials being visible in your SCS, and developers needing to know Production passwords. But that is only an initial step to resolve your immediate problem, and there are multiple solutions. See How should an application store its credentials for more ideas.

– skomisa
Jan 2 at 8:37





You should not put configuration data in code in the first place. Move the credentials to a property file, and read that file to obtain the credentials. Then the property file can be edited after deployment in different environments. This also avoids other security concerns such as credentials being visible in your SCS, and developers needing to know Production passwords. But that is only an initial step to resolve your immediate problem, and there are multiple solutions. See How should an application store its credentials for more ideas.

– skomisa
Jan 2 at 8:37













Although you have framed your question very specifically in terms of Java, since the larger issue is how to deploy application code to different environments, I'm not sure that it really belongs on SO. You might try the Information Security site instead. Your question is also inviting opinions, which could make it off topic here.

– skomisa
Jan 2 at 8:42







Although you have framed your question very specifically in terms of Java, since the larger issue is how to deploy application code to different environments, I'm not sure that it really belongs on SO. You might try the Information Security site instead. Your question is also inviting opinions, which could make it off topic here.

– skomisa
Jan 2 at 8:42














1 Answer
1






active

oldest

votes


















0














If you have multiple environments which have different databases, then the best way to handle this would be application with command line parameters. You can modify your java application to read the command line parameters and use these parameters in application.



For example --dburl = <database url> --dbusername= <db username>



And the another way will be take these paramters from environment variable. And define these variables in the system where you are deploying the applications.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999691%2fhow-to-change-some-java-variables-before-deploying-on-a-remote-server%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If you have multiple environments which have different databases, then the best way to handle this would be application with command line parameters. You can modify your java application to read the command line parameters and use these parameters in application.



    For example --dburl = <database url> --dbusername= <db username>



    And the another way will be take these paramters from environment variable. And define these variables in the system where you are deploying the applications.






    share|improve this answer




























      0














      If you have multiple environments which have different databases, then the best way to handle this would be application with command line parameters. You can modify your java application to read the command line parameters and use these parameters in application.



      For example --dburl = <database url> --dbusername= <db username>



      And the another way will be take these paramters from environment variable. And define these variables in the system where you are deploying the applications.






      share|improve this answer


























        0












        0








        0







        If you have multiple environments which have different databases, then the best way to handle this would be application with command line parameters. You can modify your java application to read the command line parameters and use these parameters in application.



        For example --dburl = <database url> --dbusername= <db username>



        And the another way will be take these paramters from environment variable. And define these variables in the system where you are deploying the applications.






        share|improve this answer













        If you have multiple environments which have different databases, then the best way to handle this would be application with command line parameters. You can modify your java application to read the command line parameters and use these parameters in application.



        For example --dburl = <database url> --dbusername= <db username>



        And the another way will be take these paramters from environment variable. And define these variables in the system where you are deploying the applications.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 6:16









        Amit NanawareAmit Nanaware

        1,1011112




        1,1011112
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999691%2fhow-to-change-some-java-variables-before-deploying-on-a-remote-server%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas