gpt4 book ai didi

java - 如何在 Linux 上安装 Java 开发环境(JDK、Maven、IDE、...) VirtualBox

转载 作者:行者123 更新时间:2023-11-30 09:41:34 25 4
gpt4 key购买 nike

如何为 Java 开发设置基于 Unix 的 VirtualBox guest ?我希望保留我现有的一些开发环境(我运行 Windows)并使用 VirtualBox 将其集成。这可能吗?

最佳答案

我花了一些时间想出了一个更灵活的解决方案,不仅可以从头开始在 Linux 上安装开发环境,还可以满足在 VirtualBox 上运行的系统的需求。

我发现通过 VirtualBox 运行两个系统在 Windows 7 旗舰版上运行提供了最佳解决方案,可以满足我作为具有额外 bash 脚本技能的基于 Java 的 Web 开发人员的需求。

让我们从我的主机系统 (Windows 7 Ultimate) 开始吧,它为我提供了一个专有环境,除了 Photoshop、MS Office、MSSQL 等工具外,我还可以从 Oracle 安装专有的 JDK。Windows 7 的 Ultimate 版本允许我设置 XP Mode 机器以将 IE6、IE7、IE8 添加到我的浏览器范围(每个旧版 Internet Explorer 都需要一台新机器)。我也可以在 Windows 上测试 Safari,但不能在 Linux 上测试(据我所知)。我使用的大多数与 Java 相关的其他工具(IDE 和 Maven、服务器)只需将其解压到特定位置或运行安装程序即可。我做出的两个关键选择是:1) 将所有内容保存在我的“%USERPROFILE%”(主)目录中 & *2)*确保我的 IDE 支持 Maven。

我们的想法是让我们的主人和客人一起工作。正如我在下面的视频中演示的那样,这两个系统可以互惠互利。我们可以在 Windows 中使用 Tortoise SVN 客户端设置 SVN 存储库,以用作访客系统中的存储库。显然,如果你想在 VirtualBox 中的 guest 上安装合适的 SVN 客户端,请安装它们。但是,您的 guest IDE 将能够使用这些 Windows 创建的存储库。您也可以通过共享文件夹并使用您的 guest SVN 客户端将其放入颠覆存储库来采用另一种方式。

我们的访客系统 (Linux) 允许我们从 Windows 中删除一些英国媒体报道软件。不再需要 FileZilla 和 Putty 之类的东西。我们的客人配备了一个内置 ftp 和 ssh 的高级终端。我们现在还可以创建 bash 脚本来构建/重建我们的 Linux 开发并下载我们的需求。您甚至可以编写 bash 脚本来下载 Maven 并将其解压缩到 Windows 共享目录中。

Linux 还为 Web 开发人员提供了一个额外的浏览器,该浏览器需要像 Konqueror 一样进行测试。

更重要的是,我们的Linux系统正好可以作为一个完全不同于我们主机的环境。我们可以设置 Open JDK 版本并相应地配置我们的 Maven 安装,这也可以在主机和 guest 之间共享,因为 JRE 从我们的主机/ guest 中抽象出来。

我编写了以下脚本,用于将 Oracle JDK 下载并安装到您的 guest 、Maven、NetBeans 和 IDEA 上。该脚本还会提示您输入一个文件来写入“引导”命令,以尝试将一些默认值(如“.m2”、“maven”、“SVN”、“NetBeansProjects”、“IDEAProjects”)从主机挂载到客户机。前提是您已经设置了带有 Guest Additions 的 VirtualBox 并设置了要共享的这些目录。

系统会提示您输入可用于写入启动命令的系统脚本文件。我希望在 Linux 上有一个通用位置,但 OpenSuse 不支持,所以您将无法使用我提供的默认位置(输入:/etc/rc.d/boot.local)。如果您不喜欢此功能,该脚本将在您的“/usr/local/bin”位置创建“即时”脚本。

最后,因为我们只在 guest 上使用共享文件夹(如果一切设置正确),删除您的 guest 应该是安全的,因为您正在从主机系统共享项目、Maven、SVN,并且数据应该还在那里。

查看此 vid

#!/bin/bash
#Author: Yucca Nel http://thejarbar.org
#Will restart system
#Modify these variables as needed...
tempWork=/tmp/work
defaultStartScript=/etc/init.d/rc.local
locBin=/usr/local/bin
javaUsrLib=/usr/lib/jvm
defaultMaven=3.0.4
defaultNetBeansVer=7.1
mavenUsrLib=/usr/lib/maven
defaultIDEA=11.0.1

sudo mkdir -p $javaUsrLib
mkdir -p $tempWork
sudo mkdir -p $mavenUsrLib
mkdir -p $HOME/.m2
mkdir -p $HOME/SVN

cd $tempWork

#Update this line to reflect newer versions of JDK...
wget http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-i586.tar.gz

#Extract the download
tar -zxvf $tempWork/*
rm -rf $tempWork/*.gz

#Move it to where it can be found...
sudo mv -f $tempWork/* $javaUsrLib/
export JAVA_HOME="$javaUsrLib/jdk1.7.0_02"

sudo ln -f -s $javaUsrLib/jdk1*/bin/* /usr/bin/
rm -rf $tempWork/*
#Update this line to reflect newer versions of JDK...

if ! grep "JAVA_HOME=$javaUsrLib/jdk1.7.0_02" /etc/environment
then
echo "JAVA_HOME=$javaUsrLib/jdk1.7.0_02" | sudo tee -a /etc/environment
fi

source /etc/environment

read -p "Please [Enter] full path name of your local startup script ($defaultStartScript is the default). Please
make sure on this before providing a value by consulting documentation for your system:" locStartScript
locStartScript=${locStartScript:-$defaultStartScript}

read -p "Please [Enter] Maven Version ($defaultMaven is default):" mavenVersion
mavenVersion=${mavenVersion:-$defaultMaven}

read -p "Please [Enter] NetBeans Version ($defaultNetBeansVer is default):" netbeansVersion
netbeansVersion=${netbeansVersion:-$defaultNetBeansVer}

read -p "Please [Enter] IDEA Version ($defaultIDEA is default):" ideaVersion
ideaVersion=${ideaVersion:-$defaultIDEA}


if [ ! -f $locStartScript ]
then
echo "The file you provided could not be found. Remember to include the full path and try again. Exiting in 7 secs..."
sleep 7
exit 1
fi

wget http://mirrors.powertech.no/www.apache.org/dist//maven/binaries/apache-maven-$mavenVersion-bin.tar.gz
tar -zxvf $tempWork/*

#Move it to a more logical location
sudo mv -f $tempWork/apache-maven-$mavenVersion $mavenUsrLib/
sudo ln -f -s $mavenUsrLib/apache-maven-$mavenVersion/bin/* /usr/bin/

#If you have Maven on Windows and use VirtualBox, you can set up the maven to be a virtualbox shared folder.
#The name must match the name used below (ignore if irrelevant to you).


if [ -f /sbin/mount.vboxsf ]
then
sudo /sbin/umount $HOME/.m2
sudo /sbin/umount $mavenUsrLib
sudo /sbin/mount.vboxsf .m2 $HOME/.m2
sudo /sbin/mount.vboxsf maven $mavenUsrLib
fi

if mountpoint -q $HOME/.m2 && mountpoint -q $mavenUsrLib
then
tar -zxvf $tempWork/*
sudo mv -f $tempWork/apache-maven-$mavenVersion $mavenUsrLib/
#Add it to the start script to automate process...
if ! grep "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" $locStartScript
then
echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $locStartScript
fi

if ! grep "sudo /sbin/mount.vboxsf maven $mavenUsrLib" $locStartScript
then
echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $locStartScript
fi
sudo chmod +x $locStartScript

#Create a mount and unmount script file...
rm -rf $tempWork/*
echo '#!/bin/bash' > $tempWork/maven-mount.sh
echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" >> $tempWork/maven-mount.sh
echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" >> $tempWork/maven-mount.sh
echo "echo 'mounted maven'" >> $tempWork/maven-mount.sh
echo "exit 0" >> $tempWork/maven-mount.sh

echo '#!/bin/bash' > $tempWork/maven-umount.sh
echo "sudo umount $HOME/.m2" >> $tempWork/netbeans-umount.sh
echo "sudo umount $mavenUsrLib" >> $tempWork/netbeans-umount.sh
echo "echo 'unmounted maven'" >> $tempWork/maven-mount.sh
echo 'exit 0' >> $tempWork/maven-umount.sh

#Script for mounting ALL VirtualBox shared solders....
#If there isn't one create one...
if [ ! -f $locBin/mount-all-from-host.sh ]
then
echo '#!/bin/bash' > /mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $tempWork/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $tempWork/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/mount-all-from-host.sh

#Otherwise if there is one, but no mount, add one...
elif ! grep "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" $locBin/mount-all-from-host.sh
then
sudo sed -ie '$d' $locBin/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf .m2 $HOME/.m2" | sudo tee -a $locBin/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $locBin/mount-all-from-host.sh

elif ! grep "sudo /sbin/mount.vboxsf maven $mavenUsrLib" $locBin/mount-all-from-host.sh
then
sudo sed -ie '$d' $locBin/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf maven $mavenUsrLib" | sudo tee -a $locBin/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $locBin/mount-all-from-host.sh

fi

#Script for unmounting ALL VirtualBox shared folders...
#If there isn't one create one...
if [ ! -f $locBin/umount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/umount-all-from-host.sh
echo "sudo umount -a -t vboxsf" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "echo 'unmounted all VirtualBox shared folders'" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/umount-all-from-host.sh
fi

chmod +x $tempWork/*
sudo mv -f $tempWork/* $locBin/
rm -rf $tempWork/*
fi

sudo ln -f -s $mavenUsrLib/apache-maven-$mavenVersion/bin/* /usr/bin/
rm -rf $tempWork/*


wget http://dlc.sun.com.edgesuite.net/netbeans/$netbeansVersion/final/bundles/netbeans-$netbeansVersion-ml-javase-linux.sh
sh $tempWork/*sh;


#Add Netbeans launcher to your PATH. Doing so allows you to run 'netbeans' command from the terminal
#This line will need to be changed if you changed the default install location (IOW Netbeans is not in ~/)
sudo ln -f -s ~/netbeans-7.1/bin/netbeans /usr/bin/;

#If you use VirtualBox , you can share your projects between Host and guest. Name of shared
#folder must match 'NetBeansProjects'
mkdir -p $HOME/NetBeansProjects

if [ -f /sbin/mount.vboxsf ]
then
sudo /sbin/umount $HOME/NetBeansProjects
sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects
fi

if mountpoint -q $HOME/NetBeansProjects
then
#Add it to the start script to automate process...
if ! grep "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" $locStartScript
then
echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" | sudo tee -a $locStartScript
fi
chmod +x $locStartScript

#Create a mount and unmount script file...
rm -rf $tempWork/*
echo '#!/bin/bash' > $tempWork/netbeans-mount.sh
echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" >> $tempWork/netbeans-mount.sh
echo "mounted NetBeansProjects" >> $tempWork/netbeans-mount.sh
echo "exit 0" >> $tempWork/netbeans-mount.sh

echo '#!/bin/bash' > /netbeans-umount.sh
echo "sudo umount $HOME/NetBeansProjects" >> $tempWork/netbeans-umount.sh
echo "unmounted NetBeansProjects" >> $tempWork/netbeans-mount.sh
echo 'exit 0' >> $tempWork/netbeans-umount.sh

#Script for mounting ALL VirtualBox shared solders....
#If there isn't one create one...
if [ ! -f $locBin/mount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" | sudo tee -a $tempWork/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/mount-all-from-host.sh

#Otherwise if there is one, but no mount, add one...
elif ! grep "sudo /sbin/mount.vboxsf NetBeansProjects" $locBin/mount-all-from-host.sh
then
sudo sed -ie '$d' $locBin/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" | sudo tee -a $locBin/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $locBin/mount-all-from-host.sh
fi

#Script for unmounting ALL VirtualBox shared folders...
#If there isn't one create one...
if [ ! -f $locBin/umount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/umount-all-from-host.sh
echo "sudo umount -a -t vboxsf" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "echo 'unmounted all VirtualBox shared folders'" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/umount-all-from-host.sh
fi

chmod +x $tempWork/*
sudo mv -f $tempWork/* $locBin/
rm -rf$tempWork/*
fi

wget http://download-ln.jetbrains.com/idea/ideaIC-$ideaVersion.tar.gz;
tar -zxvf $tempWork/*;

#Move it to a better location...
mv -f $tempWork/idea-IC-* $HOME/;
rm -rf $tempWork/*

sudo ln -f -s $HOME/idea-*/bin/* /usr/bin/;

#If you use VirtualBox , you can share your projects between Host and guest. Name of shared
#folder must match 'IdeaProjects'
mkdir -p $HOME/IdeaProjects

if [ -f /sbin/mount.vboxsf ]
then
sudo /sbin/umount $HOME/IdeaProjects
sudo /sbin/mount.vboxsf IdeaProjects $HOME/IdeaProjects
fi

if mountpoint -q $HOME/IdeaProjects
then
#Add it to the start script to automate process...
if ! grep "sudo /sbin/mount.vboxsf IdeaProjects $HOME/IdeaProjects" $locStartScript
then
echo "sudo /sbin/mount.vboxsf IdeaProjects $HOME/IdeaProjects" | sudo tee -a $locStartScript
fi
chmod +x $locStartScript

#Create a mount and unmount script file...
rm -rf $tempWork/*
echo '#!/bin/bash' > $tempWork/idea-mount.sh
echo "sudo /sbin/mount.vboxsf IdeaProjects $HOME/IdeaProjects" >> /idea-mount.sh
echo "echo 'mounted IdeaProjects'" >> $tempWork/idea-mount.sh
echo "exit 0" >> $tempWork/idea-mount.sh

echo '#!/bin/bash' > $tempWork/idea-umount.sh
echo "sudo umount $HOME/IdeaProjects" >> $tempWork/idea-umount.sh
echo "echo 'unmounted IdeaProjects'" >> $tempWork/idea-mount.sh
echo 'exit 0' >> $tempWork/idea-umount.sh

#Script for mounting ALL VirtualBox shared solders....
#If there isn't one create one...
if [ ! -f $locBin/mount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf IdeaProjects $HOME/IdeaProjects" | sudo tee -a $tempWork/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/mount-all-from-host.sh

#Otherwise if there is one, but no mount, add one...
elif ! grep "sudo /sbin/mount.vboxsf IdeaProjects" $locBin/mount-all-from-host.sh
then
sudo sed -ie '$d' $locBin/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf IdeaProjects $HOME/IdeaProjects" | sudo tee -a $locBin/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $locBin/mount-all-from-host.sh
fi

#Script for unmounting ALL VirtualBox shared folders...
#If there isn't one create one...
if [ ! -f $locBin/umount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/umount-all-from-host.sh
echo "sudo umount -a -t vboxsf" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "echo 'unmounted all VirtualBox shared folders'" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/umount-all-from-host.sh
fi

chmod +x $tempWork/*
sudo mv -f $tempWork/* $locBin/
rm -rf $tempWork/*
fi

if [ -f /sbin/mount.vboxsf ]
then
sudo /sbin/umount $HOME/SVN
sudo /sbin/mount.vboxsf SVN $HOME/SVN
fi

if mountpoint -q $HOME/SVN
then
#Add it to the start script to automate process...
if ! grep "sudo /sbin/mount.vboxsf SVN $HOME/SVN" $locStartScript
then
echo "sudo /sbin/mount.vboxsf SVN $HOME/SVN" | sudo tee -a $locStartScript
fi
chmod +x $locStartScript

#Create a mount and unmount script file...
rm -rf $tempWork/*
echo '#!/bin/bash' > $tempWork/svn-mount.sh
echo "sudo /sbin/mount.vboxsf SVN $HOME/SVN" >> /svn-mount.sh
echo "echo 'mounted SVN'" >> $tempWork/svn-mount.sh
echo "exit 0" >> $tempWork/svn-mount.sh

echo '#!/bin/bash' > $tempWork/svn-umount.sh
echo "sudo umount $HOME/SVN" >> $tempWork/svn-umount.sh
echo "echo 'unmounted SVN'" >> $tempWork/svn-mount.sh
echo 'exit 0' >> $tempWork/svn-umount.sh

#Script for mounting ALL VirtualBox shared solders....
#If there isn't one create one...
if [ ! -f $locBin/mount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf SVN $HOME/SVN" | sudo tee -a $tempWork/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/mount-all-from-host.sh

#Otherwise if there is one, but no mount, add one...
elif ! grep "sudo /sbin/mount.vboxsf SVN" $locBin/mount-all-from-host.sh
then
sudo sed -ie '$d' $locBin/mount-all-from-host.sh
echo "sudo /sbin/mount.vboxsf SVN $HOME/SVN" | sudo tee -a $locBin/mount-all-from-host.sh
echo "exit 0" | sudo tee -a $locBin/mount-all-from-host.sh
fi

#Script for unmounting ALL VirtualBox shared folders...
#If there isn't one create one...
if [ ! -f $locBin/umount-all-from-host.sh ]
then
echo '#!/bin/bash' > $tempWork/umount-all-from-host.sh
echo "sudo umount -a -t vboxsf" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "echo 'unmounted all VirtualBox shared folders'" | sudo tee -a $tempWork/umount-all-from-host.sh
echo "exit 0" | sudo tee -a $tempWork/umount-all-from-host.sh
fi

chmod +x $tempWork/*
sudo mv -f $tempWork/* $locBin/
rm -rf $tempWork/*
fi

sudo rm -rf $tempWork
sudo /sbin/reboot

exit 0

关于java - 如何在 Linux 上安装 Java 开发环境(JDK、Maven、IDE、...) VirtualBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8969809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com