I am building a UI into a JAR for Spring Server. I have a bunch of Angular JS pages. I want to pass in a command line argument to my jar that tells it where the API server is like so:

java -jar application.jar --api=http://ip:9000

So my application.properties file has:

url=${api:http://localhost:9000}

The way I am currently doing is it just having a hardocoded js config file and on each of my .html pages:

<script src="../js/appName/config.angular.js"></script>

Which contains:

var configData = {
  url:"http://localhost:9000"
};

And called in each file:

$scope.apiUrl  = configData.url;

How do I tap into the applications.properties file that I can override with my JAR command line parameter during runtime vs. the way it has been coded now.

share|improve this question
    
Are you using maven? Then you can use profiles, they provide you parameter value selection for each environment (test, prod) you can check-out from this link maven.apache.org/guides/introduction/… – webmaster 16 mins ago

Am I getting it right: The client part is delivered by the application? So the part of the last sentence 'during runtime' has more the meaning of 'bootstrap/initial loading', right? One (old school) approach is to provide the entry html (e.g. index.html) through the application (a simple template engine) and provide the needed information with a setter in a JS config object:

// pseudo js code with thymeleaf
<script th:inline="javascript">
/*<![CDATA[*/

  myConfig.url = [[${#httpServletRequest.remoteHost}]];

/*]]>*/
</script>

This is just a sample that will only set the remote host name but I think you get the idea.

Side note: I still don't really get why do you have to set this. If the application contains the client code, why do you work with absolute URLs for remote calls? (Disclaimer: I have only experience in Angular(2) and not with AngularJS)

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.