LoginSignup
2
2

More than 3 years have passed since last update.

vagrant java 構築

Last updated at Posted at 2019-10-15

2019年3月から続けたruby類の勉強を一旦止め、今はjavaを技術書を用いて触っています。
最近、電子書籍用に10タブのarrows f-03gを中古で購入し、勉強が捗ってます。
java用に新しく仮想環境を用意したので、メモとして。rubyの時と殆ど同じだけど。

ローカル環境

  • ホストOS:Windows10(※Windows Insider Program
  • エディタ:VSCode
  • 実装RAM:16GB
  • vagrant version:2.2.3

用意したいもの

  • virtualboxとvagrantの準備は割愛
  • 仮想環境OS:Ubuntu(※bento/ubuntu-18.04)
  • VSCode remote機能利用ここ要参照
  • java類:openJDK11
  • その他:git
  • DB:PostgreSQL

実内容

先述の通り、virtualboxとvagrant自体の準備は割愛。

terminal
#vagrantfileの作成
vagrant init
vagrantfile.rb
# コメントアウト部分は殆ど省略
Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-18.04"

  # vagrant name
  # 既に仮想環境"default"が1つ存在しているので、適当に名前変更
  config.vm.define "JvUbuntu"

  config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.provider "virtualbox" do |vb|
    # Customize the amount of memory on the VM:
    # 自分のPC等に合わせて
    vb.memory = "8192"
  end

  # 環境構築自動化させたいなら、下を弄ればいいのだろう。
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

仮想環境の立ち上げ

terminal
vagrant up

VSCode remoteの準備

必要な拡張機能は用意しとく

sshログイン情報の確認

terminal
vagrant ssh-config

### こんなのが出てくる
Host JvUbuntu
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/Yudai/vm/MyVagrant/JvUbuntu/.vagrant/machines/JvUbuntu/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

SSH Configuration file編集、接続

  1. VSCode上で、表示>コマンドパレット> Remote-SSH:Open Configuration Fileで開き、上のsshログイン情報をコピペ。
  2. 同じくコマンドパレットで、Connect to HostでJvUbuntuを開く

java, gitの準備

ssh内
sudo apt update
sudo apt install git
sudo apt install openjdk-11-jdk

# 一応確認
java --version

Hello world

# hello.java作成
nano hello.java

コード

hello.java
public class hello{
  public static void main(String[] args){
    System.out.println("Hello Java World!!");
  }
}
terminal
# コンパイル
javac hello.java
# => hello.class作成

# 実行
java hello
# => Hello Java World!!

DB類

今回はPostgreSQLを準備

postgresql

terminal
# install
sudo apt install postgresql

# admin作成
sudo -u postgres createuser admin -s

# adminでpostgresqlにログイン
sudo -u postgres psql
postgresql
# adminユーザのパスワード設定
\password admin

# ポスグレからquit
\q

おわり。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2