设为首页 收藏本站
查看: 510|回复: 0

[经验分享] Ubuntu + IntelliJ + Maven + Jetty + JRebel

[复制链接]

尚未签到

发表于 2017-2-27 11:47:32 | 显示全部楼层 |阅读模式
http://flurdy.com/docs/intellij/
Ubuntu + IntelliJ + Maven + Jetty + JRebel



  • by flurdy |
  • @flurdy |
  • feedback |
  • hire me |
  • donate/shirts |
  • more docs
  


        |  MoreTable of contents

  • Aim

    • Why?
    • Prerequisites

  • Java

    • Install Java
    • Configure Java

  • Maven

    • Install Maven
    • Configure Maven

      • Settings.xml

    • Download the internet

  • JRebel

    • Jrebel license
    • Download Jrebel
    • Install Jrebel
    • Configure Jrebel

  • IntelliJ IDEA

    • Intellij license
    • Download IntelliJ
    • Install IntelliJ

      • Add IntelliJ to the menu

    • Configure IntelliJ

      • Configure Maven in IntelliJ
      • Install & configure
        JRebel plugin in IntelliJ


  • Your project

    • Import project into IntelliJ

  • Jetty

    • Run Jetty in IntelliJ

  • Extensions

    • Compile on Save

  • References
  • Feedback
DSC0000.png
shirts.flurdy.com
us | uk | eu

1 Aim

  • Main aim is to use IntelliJ IDEA in Ubuntu for Java based web applications.
  • With Maven and Jetty through its plugin as the server
  • And speeding up development with JRebel
1.a Why?
The combination of Ubuntu, IntelliJ, Maven, Jetty and JRebel enables really quick web app development in Java.

  •   Ubuntu. Feel handicapped when forced to use dumbdowned Windows at work.
  •   Maven. A build system with flaws but still better than most, and especially important as it is used by most projects.
  •   IntelliJ IDEA. An IDE with many ingenious little tricks to make development speedier  and feels very comfortable to use. At work my IDE is often either Eclipse on some projects as it often is the company standard, or NetBeans when work refuse to buy IntelliJ licenses. But with some clients and at home with my FOSS license  I am much more productive with IntelliJ.
  •   Jetty. A standalone java web application server. It is quick and very light. The Maven plugin for it makes it easy to bundle and launch locally. It also then allows for very swift development cycles.
  •   JRebel. JRebel (Née JavaRebel)  reloads java classes dynamically and allows even swifter development cycles, by negating the need to ever redeploy. This saves a lot of time, thus money, and improves quality with quicker feedback loops.
And I need these tools to work together seamlessly.
1.b Prerequisites

  • Ubuntu
      I will assume you have a normal version of Ubuntu Desktop installed. This guide was based upon Ubuntu 10.04 lucid lynx.
  • Project
      A normal java based webapp project  buildt with maven that are using the jetty plugin is assumed to be checked out on your machine. If you do not have one set up,  you can read up on java,  maven &  jetty and clone an example app of mine.
2 Java
2.a Install Java
  sudo aptitude install sun-java6-jdk
2.b Configure Java
In case of other Java JDK are installed, choose Sun's flavour
  sudo update-alternatives --config java sudo update-alternatives --config javac
Environment variables
  sudo vi /etc/profile.d/java.sh  export JAVA_HOME=/usr/lib/jvm/java-6-sun
export JDK_HOME=/usr/lib/jvm/java-6-sun  sudo chmod +x /etc/profile.d/java.sh

3 Maven
3.a Install Maven
Your choice: either install via Ubuntu package repository or download the full Maven directly. The repository version depends on a load of unneccesary packages such as gjc, Ant etc. So most people recommend using the apache.org dowload instead.
For this howto I will utilise the repository version, but the only difference afterwards is the path. (You may try and restrict the installation of optional packages...)
  sudo aptitude install maven2
If you prefer the downloaded archive then do this instead:
   tar xzf apache-maven-2.2.1.tar.gz;
sudo mkdir /opt/apache;
sudo mv apache-maven-2.2.1 /opt/apache/maven-2.2.1;
cd /opt/apache;
sudo ln -s maven-2.2.1 maven;
And refer to /opt/apache/maven instead of /usr/share/maven2 in the paths below.
3.b Configure Maven
Some programs depend on different environment variables for Maven.
Also the default memory assignment is very low so you may optionally add it.
  sudo vi /etc/profile.d/maven.sh  export MAVEN_HOME=/usr/share/maven2
export M2_HOME=/usr/share/maven2
#export MAVEN_OPTS=-Xms128M -Xmx512M -XX:MaxPermSize=256m
#export MAVEN_OPTS=-noverify -javaagent:$JREBEL_HOME/jrebel.jar
  sudo chmod +x /etc/profile.d/maven.sh
3.b.i Settings.xml
Depending on your project you may need to configure the default maven settings, such as any mirrors you use, passwords, other repositories, profiles etc.
But that is out of scope of this document.
   mkdir  ~/.m2;
vi  ~/.m2/settings.xml  
3.c Download the internet
Because of maven dependency characteristics it is wise to do an initial a simple clean & build of your application do download all the  dependencies, and the special go-offline goal. Remember to include any potential profiles if they have dependencies. ( -P profile1,profile2....)
This may take a while.... But you only have to do it once (ish..)
   cd /path/to/your/project,
mvn clean;
# Wait a little while....
mvn dependency:go-offline;
# Wait a long while....
mvn install;
# Wait a longer while....
mvn jetty:run;
# Wait a longish while....
When ready kill Jetty with ^C (As in ctrl+c)
Remember from now on you should mostly do append -o parameter (offline) to speed up builds.
  

4 JRebel
4.a JRebel license
You need to obtain a license to run JRebel.
You can use the trial version for 30 days. (Its worth it)
Note: ZeroTurnaround do offer free licenses for open source developers.
4.b Download JRebel
Download the generic JAR installer
4.c Install JRebel
   cd /tmp;
unzip ~/Downloads/jrebel-*-setup.zip;
sudo -jar jrebel/jrebel-setup.zip
I tend to choose /opt/ZeroTurnaround/JRebel as my install path, but the default it /usr/local/ZeroTurnaround/Jrebel.
4.d Configure JRebel
If the installer doesn't trigger the configuration, or you want to reconfigure:
  sudo /opt/ZeroTurnaround/JRebel/bin/jrebel-config.sh

  • Choose "IntelliJ 8.x or later" as IDE
  • Tick "I use maven to build my application"
  • Tick "I run the server from my IDE"
  • Click Next and read how JRebel integrates with IntelliJ.
  • Click Next and read how JRebel integrates with Maven, you may want to update your projects Pom file.
  • Click Next and read how the servers inside IDEs are affected.
  • A usefull tip is the ctrl+s remaped keyboard shortcut
  • In the top right click on "Configure manually"
  • In "Java version" choose "Java 5 or later"
  • In "Operating System" choose "Unix-like (Linux, Mac OS C, etc)"
  • In "Server" choose "Maven Jetty Plugin"
  • Read how you should update your projects pom.xml by setting the scanIntervalseconds to 0
  • Add the jrebel line to maven opts sudo vi /etc/profile.d/maven.sh And then uncomment or add the MAVEN_OPTS line: export MAVEN_OPTS="-noverify -javaagent:/opt/ZeroTurnaround/JRebel/jrebel.jar $MAVEN_OPTS"
  • Click Next
  • Tick "Log to file"
  • Set "Custom log file location" to "/var/log/jrebel/jrebel.log". Create the jrebel log folder:  sudo mkdir /var/log/jrebel;
    sudo chown jrebel:jrebel /var/log/jrebel
  • Pick your plugins..
  • Click Next and Finish
  sudo vi /etc/profile.d/jrebel.sh  export JREBEL_HOME=/opt/ZeroTurnaround/JRebel  sudo chmod +x /etc/profile.d/jrebel.sh

5 IntelliJ IDEA
5.a  IntelliJ license
Decide which version you want. I will assume a trial of the ultimate edition.
Note: JetBrains do offer free licenses for IntelliJ Ultimate for open source developers.
5.b Download IntelliJ
Go to JetBrains IntelliJ download page, and download the most recent version.
5.c Install IntelliJ
Like JRebel I prefer /opt/jetbrains as my install location. You may prefer directly in /opt or in /usr/local, etc.
   cd /tmp;
tar xzf ~/Downloads/ideaIU-10.0.1.tar.gz;
sudo chown -R root:root idea-IU-99.32;
sudo mkdir /opt/jetbrains;
sudo mv idea-IU-99.32 /opt/jetbrains/;
sudo cd /opt/jetbrains;
sudo ln -s idea--IU-99.32 idea;  
5.c.i Add IntelliJ to the menu

  • Select System/Preferences/Main Menu
  • In the left column, select Programming
  • Click New item
  • Enter "IntelliJ IDEA" as the Name
  • Enter /opt/jetbrains/idea/bin/idea.sh as the Command
  • Click on the icon on the left to choose icon.
  • Enter /opt/jetbrains/idea/bin/ in the Location field
  • Choose idea128.png as the icon and click on Open
  • Then OK, then Close
5.d Configure IntelliJ
On first launch IntelliJ will ask you a series of questions regarding plugins etc.
Choose maven plugin amongst others.
5.d.i Configure Maven in IntelliJ
Open settings via File/Settings/maven and enter Maven home directory as /usr/share/maven2
5.d.ii Install & configure JRebel plugin in IntelliJ

  • Open the plugins section via File/Settings/Plugins
  • Choose the Available tab
  • Search for JRebel
  • Right click on JRebel Plugin and choose Download and install
  • Once installed go to File/Settings/JRebel
  • Enter /opt/ZeroTurnaround/JRebel/jrebel.jar in JRebel location
  

6 Your project
6.a Import project into IntelliJ

  • Find your project via File/New project
  • Choose Import project from External model
  • Select Maven
  • Find your project root
  • Check Environment settings still refer to /usr/share/maven2 as Maven location
  • Wait awhile for IntelliJ to load the new project information
  

7 Jetty
7.a Run Jetty in IntelliJ

  • In IntelliJ, click to open Maven Projects on the right hand side
  • Expand

    • your project
    • Plugins
    • Jetty

  • Right clik on jetty:run
  • I choose the top option Run Maven build, which is the same as if I double clicked on jetty:run.
    ( Others say you should choose Run with JRebel, but the top option works for me,  and the JRebel action actually gives me an error  that maven is not configured...)
  

8 Extension
8.a Compile on save
IntelliJ does not support Compile-on-save / Auto-build.
This feature is essential to get the best time saving from using JRebel.
So you will have to manually enter ctrl++shift+F9 to compile your file, or just ctrl+F9 to build your whole project.
A decent work around is to map ctrl+s as the build command.
Another is to install a plugin called Eclipse Mode, which auto build like eclipse.
(I have not been able to get this to work as expected)
  

9 References

  • Matt Raible's tips on IntelliJ on Mac OS X
  

10 Feedback

  • If you find any elements are missing, please let me know.
  • If you spot any errors, please let me know.
  • If there are elements you want to discuss, the Ubuntu forums are very busy and usefull.
  • If you found this helpfull, why not buy a t-shirt from my shop?
  • If you would like committed help from me, consider hiring me?
  • If you write/find similar howto, or even one based on these,  please let me know so I can link to it!


  • flurdy |
  • @flurdy |
  • feedback |
  • hire me |
  • donate/shirts |
  • more docs


  • (
  • started May 2010 |
  • last updated January 2011
  • )

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-347949-1-1.html 上篇帖子: Jetty使用内存过大的解决方案 下篇帖子: eclipse+maven+jetty+struts2 HelloWorld
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表