Skip to content

Instantly share code, notes, and snippets.

@nobeans
Last active August 29, 2015 10:05
Show Gist options
  • Save nobeans/9ebc732d72ffcd82b185 to your computer and use it in GitHub Desktop.
Save nobeans/9ebc732d72ffcd82b185 to your computer and use it in GitHub Desktop.
JavaScript to create a command line of CLI at Spring Initializr site (https://start.spring.io/ )
var groupId = document.getElementById('groupId').value;
var artifactId = document.getElementById('artifactId').value;
var name = document.getElementById('name').value;
var description = document.getElementById('description').value;
var packageName = document.getElementById('packageName').value;
var type = document.getElementById('type').value;
var packaging = document.getElementById('packaging').value;
var javaVersion = document.getElementById('javaVersion').value;
var language = document.getElementById('language').value;
var bootVersion = document.getElementById('bootVersion').value;
var dependencyNames = []
var dependencies = document.querySelectorAll("#dependencies input:checked");
for (var i = 0; i < dependencies.length; i++) {
dependencyNames.push(dependencies[i].value);
}
var commands = ['spring', 'init'];
commands.push('--groupId=' + groupId);
commands.push('--artifactId=' + artifactId);
commands.push('--name=' + name);
//commands.push('--description="' + description + '"'); // to avoid the issue: https://github.com/spring-projects/spring-boot/issues/3841
//commands.push('--packageName=' + packageName); // not supported by cli yet: 3.0.0.M4
commands.push('--type=' + type);
commands.push('--packaging=' + packaging);
commands.push('--java-version=' + javaVersion);
commands.push('--language=' + language);
commands.push('--boot-version=' + bootVersion);
commands.push('--dependencies=' + dependencyNames.join(','));
prompt("Copy to clipboard", commands.join(' '));
@nobeans
Copy link
Author

nobeans commented Aug 28, 2015

  1. Make a bookmark with a name like To Spring Boot CLI at your browser.

    javascript:var groupId=document.getElementById("groupId").value;var artifactId=document.getElementById("artifactId").value;var name=document.getElementById("name").value;var description=document.getElementById("description").value;var packageName=document.getElementById("packageName").value;var type=document.getElementById("type").value;var packaging=document.getElementById("packaging").value;var javaVersion=document.getElementById("javaVersion").value;var language=document.getElementById("language").value;var bootVersion=document.getElementById("bootVersion").value;var dependencyNames=[];var dependencies=document.querySelectorAll("#dependencies input:checked");for(var i=0;i<dependencies.length;i++){dependencyNames.push(dependencies[i].value)}var commands=["spring","init"];commands.push("--groupId="+groupId);commands.push("--artifactId="+artifactId);commands.push("--name="+name);commands.push("--type="+type);commands.push("--packaging="+packaging);commands.push("--java-version="+javaVersion);commands.push("--language="+language);commands.push("--boot-version="+bootVersion);commands.push("--dependencies="+dependencyNames.join(","));prompt("Copy to clipboard",commands.join(" "));
    

    (This is minified by http://syncer.jp/minifier.)

  2. Visit the site of https://start.spring.io/

  3. Input and check the form for your requirement.

  4. Use the bookmarklet.

  5. Copy the command line text of the dialog.

  6. Paste to your console in a directory as the root of your new project. (Requires spring-boot-cli. Please install it by GVM, etc.
    cf. http://docs.spring.io/autorepo/docs/spring-boot/1.2.0.M2/reference/htmlsingle/#getting-started-installing-the-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment