Linux上Java開發的常見實踐是什么?

[英]What are the Common Practices for Java Development on Linux?


I'm trying to migrate from Windows to Linux as a Java development platform, and while the transition has generally been pretty painless, there are a few points of uncertainty that I'd like some feedback on. I'm running openSUSE 11.4, but I'm open to hear what works on other distros.

我正試圖將Windows作為Java開發平台從Linux遷移到Linux,雖然轉換過程通常相當輕松,但我希望得到一些不確定因素的反饋。我正在運行openSUSE 11.4,但我願意聽聽其他發行版的工作。

  1. Where do you install your JDK from? This one is surprisingly not as cut and dry as most people make it out to be. OpenJDk 6 is available in the openSUSE repositories, and was very easy to install. However it's currently update 21, and right now the Oracle release is at update 24. I'm used to a little alert in Windows notifying me that my Java needs updating but that doesn't appear to be the norm in Linux. Do Java developers forgo the JDK in their package manager and install the binary directly? Or is there another way?
  2. 您從哪里安裝JDK ?令人驚訝的是,這一款並不像大多數人想象的那么干癟。OpenJDk 6在openSUSE存儲庫中是可用的,並且非常容易安裝。但是,它目前是更新21,現在Oracle的版本是更新24。我習慣了Windows中的一個小警告,通知我我的Java需要更新,但這似乎不是Linux的標准。Java開發人員是否放棄了包管理器中的JDK,直接安裝二進制文件?還是有別的辦法?
  3. Where do you install Eclipse? There seems to be a general agreement online that Eclipse is best installed by simply downloading the binary and extracting it somewhere, but where's the usual place I would extract a program like Eclipse or Ant? I've seen votes for /usr/local and /opt online, but no definitive answer.
  4. 在哪里安裝Eclipse?在線上似乎有一種普遍的共識,即只要下載二進制文件並將其提取到某個地方,就可以安裝Eclipse,但是通常我提取Eclipse或Ant這樣的程序的地方在哪里呢?我在網上看到了對/usr/local和/opt的投票,但沒有明確的答案。
  5. Where do you put your Jetty/Tomcat? Similar to the eclipse question, where do most Linux Java developers put their Jetty/Tomcat/other container.
  6. 你把防波堤/Tomcat放在哪里?與eclipse問題類似,大多數Linux Java開發人員將Jetty/Tomcat/其他容器放在哪里。
  7. What are some of the differences between the way you setup development versus production At the very least it seems I don't want to run my servlet container as root, that makes sense to me. But what other practices should I watch out for? Is there anything else that could make my development environment easier, but perhaps less secure?
  8. 設置開發和生產的方式有什么不同至少看起來我不希望以root身份運行servlet容器,這對我來說是有意義的。但是我還需要注意哪些其他的實踐呢?還有什么能讓我的開發環境更簡單,但可能更不安全?

I found this question was similar but ultimately too high level and didn't get into details of how actual developers are setting up their environment. If there's other resources you feel answer these questions, please share them here.

我發現這個問題很相似,但最終還是太高了,並且沒有深入到實際開發人員如何設置他們的環境的細節。如果你有其他的資源可以回答這些問題,請在這里分享。

Thanks for your time.

謝謝你的時間。

6 个解决方案

#1


7  

Q> Where do you install your JDK from?
A> I never bother with other JDKs coming from outside Sun/Oracle mainly because our product is only certified to work with Sun/Oracle JRE. On my desktop, I run Kubuntu, but I never use apt-get for this but always download them manually. Reasons:

Q>您從哪里安裝JDK ?在>,我從不打擾其他來自Sun/Oracle的jdk,主要是因為我們的產品只有Sun/Oracle JRE的認證。在我的桌面上,我運行Kubuntu,但是我從來沒有使用apt-get來實現它,但是我總是手動下載它們。原因:

  • distro maintainers rarely rush to upgrade packages, as their primary concern is to make dependant apps (such as OpenOffice) work. If JDK changes from 1.6.0_20 to 1.6.0_21, they simply don't care. I might do because a newer patch might have an important bugfix or I simply want to try if my app still passes all the unit tests.
  • 發行版維護人員很少急於升級包,因為他們最關心的是讓依賴的應用程序(比如OpenOffice)工作。如果JDK從1.6.0_20更改為1.6.0_21,他們根本不在乎。我這樣做可能是因為一個更新的補丁可能有一個重要的錯誤修正,或者我只是想嘗試一下我的應用是否仍然通過所有的單元測試。
  • it might be a nightmare to retain old JDK versions. We still support older versions of our product and if I upgrade to a newer Kubuntu, I don't have guarantees that some ancient JDK will still be available as a package.
  • 保留舊的JDK版本可能是一場噩夢。我們仍然支持我們的產品的舊版本,如果我升級到一個新的Kubuntu,我不能保證一些古老的JDK仍然可以作為一個包使用。
  • I am not sure some distros even support multiple existence of JDKs on the same machine.
  • 我不確定某些發行版是否支持在同一台機器上存在多個jdk。

My preference is to keep all JDKs/JREs in /opt and make a symlink to the newest one or the one I need most. I simply don't see why installing JDK manually is a problem.

我更喜歡將所有的jdk /JREs保存在/opt中,並與最新的或者我最需要的版本進行符號鏈接。我只是不明白為什么手動安裝JDK是一個問題。

I also set the PATH to the newest JDK/JRE.

我還設置了到最新JDK/JRE的路徑。

Same thing (and similar arguments) apply to Ant and Maven.

同樣的事情(以及類似的參數)也適用於Ant和Maven。

Q> Where do you install Eclipse?
A> I use IntelliJ but the same applies. I store IDE in my home folder. This allows me to have different versions of it, update them without needing sudo, etc. I could as well install it in /opt but I guess I got this habit when I was downloading and testing newest IntelliJ IDEA EAP every week so I can quickly delete the older versions and do not pollute /opt. Finally, other programs might require Ant/Maven/JDK but it's only me who uses IntelliJ hence the different approach.

Q>在哪里安裝Eclipse?>我使用IntelliJ,但同樣適用。我將IDE存儲在我的home文件夾中。這讓我有不同的版本,不需要更新sudo,等等。我也可以安裝在/ opt但我想我有這個習慣當我下載和測試最新IntelliJ IDEA EAP每周我可以快速刪除舊版本,不污染/ opt。最后,其他程序可能需要Ant/Maven/JDK,但只有我使用IntelliJ,因此采用了不同的方法。

Q> Where do you put your Jetty/Tomcat?
A> I have a separate folder tomcats under /home where I have ~10 different Tomcat instances. Each of Tomcats is used for a different version of my app (we bundle Tomcat with our app). This is necessary because one deployment of our app can have different Tomcat settings (or even version) than another.

Q>你把你的防波堤/Tomcat放在哪里?我在/home有一個單獨的文件夾tomcats,其中有大約10個不同的Tomcat實例。每個Tomcats都被用於我的應用的不同版本(我們將Tomcat和我們的應用捆綁在一起)。這是必要的,因為我們的應用程序的一個部署可以有不同的Tomcat設置(甚至版本)。

Q> What are some of the differences between the way you setup development versus production
A> It very much depends on your app. For example, we need some partitions to have lower access latencies but having less space (e.g. gigabytes for Lucene indexes) VS others which can have higher latencies but require more space (e.g. terabytes for content repositories). We, however, design our app so that all these different aspects can reside on different partitions which are configurable. Some partitions need to have special limitations (e.g. file upload) so this doesn't overflow other partitions. There is no simple one-for-all answer to this question, but obviously most of these concerns don't matter that much for a development environment.

問>之間的一些差異是什么你設置開發和生產>的方式很大程度上取決於您的應用程序。例如,我們需要一些分區訪問延遲較低但是有更少的空間(例如g Lucene索引)和其他人可以有更高的延遲,但需要更多的空間(如字節內容存儲庫)。然而,我們設計了應用程序,以便所有這些不同的方面都可以駐留在可配置的不同分區上。有些分區需要有特殊的限制(例如文件上傳),這樣就不會溢出其他分區。對於這個問題,沒有一個簡單的答案,但是很明顯,大多數的這些問題對於開發環境來說並不重要。

#2


3  

Where do you install your JDK from?

您從哪里安裝JDK ?

I use Arch Linux myself, and we have the oracle jdk/jre in the repository itself. Hence, use your distro-repository if it has the oracle jdk/jre else get it from oracle itself.

我自己使用Arch Linux,並且在存儲庫中有oracle jdk/jre。因此,如果它有oracle jdk/jre,則使用您的distro存儲庫,否則從oracle本身獲取它。

Where do you install Eclipse?

在哪里安裝Eclipse?

Again, the same answer as above applies to this as well. If however, there is any issue with the distro provided version, I always put my custom installs in /opt/ - /opt/java , /opt/eclipse, /opt/netbeans - etc. I dont install stuff in my home folder (except in circumstances where I don't have permission anywhere else - rare), since that would mean that other users would need access to my home folder to run the stuff. I don't want production (or development for that matter) stuff having direct access to my home.

同樣,上面的答案同樣適用於這個。但是,如果有任何問題與發行版提供的版本,我總是把我的自定義安裝在/ opt /,/ opt / java / opt / eclipse / opt / netbeans -等等。我不安裝的東西在我家文件夾(除了在我沒有允許的情況下,其他地方-罕見),因為這意味着其他用戶需要訪問我家文件夾運行。我不希望生產(或開發)的東西能直接進入我家。

Where do you put your Jetty/Tomcat?

你把防波堤/Tomcat放在哪里?

The same answer as above applies here as well. Only in circumstances, where I have installed more than one version, I create an /opt/experimental/ and install there so that I know which one my production is running and which one I can remove when no longer required.

同樣的答案也適用於這里。只有在我安裝了多個版本的情況下,我才創建/opt/experimental/並在那里安裝,這樣我才能知道我的產品正在運行哪個版本,以及在不再需要時可以刪除哪個版本。

What are some of the differences between the way you setup development versus production?

您設置開發和生產之間的差異有哪些?

If possible, I always setup different machines for production and development work. Different computers, but exactly identical setup. The only systems that can push code to the production system are those in the development group. Where this segregation is not possible, I prefer to have different install for the servers, so that while I am tweaking the development configuration, my main servers don't crash or something. Also development setup will generally include a clean_up script that makes it ready for production (dropping unnecessary priviledges for db accounts, cleaning up, etc.

如果可能的話,我總是為生產和開發工作設置不同的機器。不同的電腦,但設置完全相同。能夠將代碼推送到生產系統的唯一系統是開發團隊中的那些系統。在不可能實現這種隔離的地方,我更喜歡對服務器進行不同的安裝,以便在調整開發配置時,我的主服務器不會崩潰或發生其他情況。此外,開發設置通常還將包含一個清理腳本,該腳本使其可以用於生產(刪除db帳戶的不必要的特權,清理等等)。

Have whatever, setup you will, just make sure you have different database setup for development and production purposes.

無論如何,只要確保有不同的數據庫設置用於開發和生產目的。

#3


2  

The Sun version of Java for openSUSE is on the nonOSS disk (go here and scroll down for an ISO), which is an additional disk image, not part of the main install disk ISO (or you can pull the RPMs from here).

openSUSE的Sun版本是在nonOSS磁盤上(到這里,向下滾動一個ISO),這是一個額外的磁盤映像,而不是主安裝磁盤ISO的一部分(或者您可以從這里拉出rpm)。

As far as eclipse is concerned, if I'm installing at the system level, I tend to drop it in /opt. You might want to read this article on how best to handle plugins.

就eclipse而言,如果我在系統級安裝,我傾向於將它放在/opt中。您可能想要閱讀這篇關於如何最好地處理插件的文章。

(Don't let them steer you off openSUSE, it is the best distro for KDE IMO.)

(別讓他們把你趕出openSUSE,這是KDE IMO最好的發行版。)

#4


1  

Working with linux is a lot less hand holding then the windows environment that you're use too. If I were you I would switch distros to either RedHat or Ubuntu, I use to use SUSE and never looked back since I switched.

使用linux比使用windows環境要少得多。如果我是你,我會把distros換成RedHat或者Ubuntu,我過去經常用SUSE,自從我換了以后就再也不回頭看了。

You can put your JDK/Eclipse/Tomcat binaries in a couple of different places. If you are the only one going to be using them I suggest you put them in your home directory somewhere. For your Eclipse/Tomcat stuff you can but them in a local bin and then add that local bin to your PATH in your .bashrc. You can also set the location of your JDK to a JAVA_HOME env variable in your bash. If you need any more specific help with setup let me know.

您可以將JDK/Eclipse/Tomcat二進制文件放在幾個不同的位置。如果你是唯一使用它們的人,我建議你把它們放在你的主目錄的某個地方。對於您的Eclipse/Tomcat,您可以在本地bin中使用它們,然后將本地bin添加到您的.bashrc中。您還可以將JDK的位置設置為bash中的JAVA_HOME env變量。如果您需要更具體的安裝幫助,請告訴我。

#5


1  

1) We have had several problems with OpenJDK (bugs, etc) so we always use the sun jdk.

我們有幾個OpenJDK的問題(bug等),所以我們總是使用sun jdk。

2/3) A good rule to live by when living in Linux, is always install your custom software under your home folder. Linux needs to be reinstalled from time to time, but everything in your home folder is in a separate disk-partition, so it lives on. I always installs/unzips custom software such as eclipse to /home/myuser/opt, so my eclipse lives at ~/opt/eclipse. I also symlinks the eclipse-binary to my /home/myuser/bin folder for easy access. When I upgrade or change any software, I just rewire the symlink.

2/3)生活在Linux下的一個好習慣是,總是在你的家庭文件夾下安裝你的定制軟件。Linux需要不時地重新安裝,但是您的主文件夾中的所有內容都位於一個獨立的磁盤分區中,因此它仍然存在。我總是安裝/解壓縮自定義軟件,例如eclipse到/home/myuser/opt,因此我的eclipse位於~/opt/eclipse。我還將eclipsebinary與我的/home/myuser/bin文件夾相關聯,以方便訪問。當我升級或更改任何軟件時,我只是重新連接symlink。

4) Production and development environments should be as close as possible to identical. This elimenate loads of bugs caused by different configurations etc.

4)生產和開發環境要盡可能的接近相同。這種由不同配置引起的臭蟲的大量存在。

#6


0  

I create a /usr/local/java directory and unpack the JDK(s), Eclipse, Maven, Ant, Groovy and Grails in there, then create symlinks to /usr/local/bin.

我在其中創建了一個/usr/local/java目錄,並解壓縮JDK、Eclipse、Maven、Ant、Groovy和Grails,然后創建到/usr/local/bin的符號鏈接。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/03/16/72f751967d2ca042a5cfa411dca8e03e.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com