Java

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Java and the translation is 40% complete.
Outdated translations are marked like this.

Java é uma linguagem de programação originalmente desenvolvida pela Sun Microsystems que utiliza um runtime para executar aplicações Java em diversas plataformas. É uma escolha popular para desenvolvedores que desejam criar aplicações multiplataforma.

O que é Java?

Visão Geral

Java é uma linguagem de programação desenvolvida pela Sun Microsystems. A linguagem é orientada a objetos e projetada para rodar em várias plataformas sem a necessidade de recompilar o código em cada uma delas. Embora Java possa ser compilado como um programa nativo, a maior parte de sua popularidade pode ser atribuída à sua portabilidade, junto com outras características, como gerenciamento automático de memória. Para tornar a independência de plataforma possível, o compilador do Java compila o código Java para uma representação intermediária, chamada "Java bytecode" que roda em uma JVM (Java Virtual Machine) e não diretamente no sistema operacional.

Para executar o Java bytecode, é preciso ter o JRE (Java Runtime Environment) instalado. O JRE fornece bibliotecas principais, uma Máquina Virutal Java dependente da plataforma, plugins para browsers, entre outras coisas. O JDK (Java Development Kit) adiciona ferramentas de programação, como um compilador de bytecode e um debugger.

Linguagens JVM

A Máquina Virtual Java não é utilizada exclusivamente pela linguagem Java. Várias linguagens de programação utilizam a plataforma Java e rodam na JVM. Exemplos incluem: Clojure, Apache Groovy, Kotlin ou Scala.

Instalando uma máquina virtual

As escolhas

Gentoo fornece vários Java Runtime Environments (JREs) e Java Development Kits (JDKs). As opções atuais incluem:

Vendor JDK JRE
IcedTea Open Java SE (antes icedtea6-bin) dev-java/icedtea e dev-java/icedtea-bin
OpenJDK dev-java/openjdk e dev-java/openjdk-bin
Java da Oracle dev-java/oracle-jdk-bin dev-java/oracle-jre-bin
GCJ IcedTea GNU GCC Java (atualmente IcedTea-7) dev-java/icedtea sys-devel/gcc USE="gcj"

| The IcedTea Open Java SE (formerly icedtea6-bin) | dev-java/icedtea and dev-java/icedtea-bin |-

|}

Instalando o JRE/JDK

Para instalar o JDK padrão do perfil, execute:

root #emerge --ask virtual/jdk

Para instalar o JRE padrão do perfil, execute:

root #emerge --ask virtual/jre
Nota
Esteja ciente que cada JDK inclui também um JRE; instalar um JRE não é necessário se um JDK já está instalado.

Configurando um JRE headless

Sometimes there is no need for a full JRE with all the capabilities of java. Using java on a server often does not require any GUI, graphical, sound or even printer related features. To install a simplified (sometimes also referred to as headless) JRE, a few USE flags need to be changed for the selected JRE flavor.

FILE /etc/portage/package.useRequired USE flag changes
dev-java/icedtea headless-awt -alsa -cups
dev-java/icedtea-bin headless-awt -alsa -cups
dev-java/openjdk headless-awt -alsa -cups
dev-java/openjdk-bin headless-awt -alsa -cups

Depending on the current Gentoo profile, this might already be the case. As usual, the USE flag settings that are applicable to a particular package can be checked by running emerge in pretend mode:

user $emerge --pretend --verbose virtual/jre

Configurando a Máquina Virtual Java

Visão Geral

Gentoo tem a capacidade de ter múltiplos JDKs e JREs instalados sem causar conflitos.

Configurando uma máquina virtual padrão

Executando o comando java-config com a opção --list-available-vms irá produzir uma lista de todos os JREs a JDKs instalados no sistema. Por exemplo:

root #java-config --list-available-vms
The following VMs are available for generation-2:
1)      IcedTea JDK 7.2.6.3 [icedtea-7]
*)      IcedTea JDK 3.0.1 [icedtea-8]

O * indica que esta é a JVM ativa atual(system-vm ou user-vm quando configurada). O nome entre colchetes ([]) é o identificador ou ID dessa VM específica. O identificador ou o número para java-config --set-system-vm pode ser usado para definir a VM. O texto seguinte fornece um exemplo de como configurar a VM do sistema.

root #java-config --set-system-vm icedtea-7
Now using icedtea-7 as your generation-2 system JVM

Método alternativo: selecione a VM pelo número identificador:

root #java-config --set-system-vm 3
Now using icedtea-7 as your generation-2 system JVM
Nota
source-ing the profile for existing shell sessions is not usually needed when changing the user or system VM. The only exception is that variables such as JAVA_HOME will still point to the old location after setting a user VM for the first time or revert back to the system VM.

Java browser plugins

Importante
O suporte ao plugin Java foi depreciado no JDK 9[1].
Nota
Note that Chromium-based browsers since version 42 and Firefox since version 52 no longer support NPAPI-based plugins[2]. This effectively disables the Java plugin on modern browsers.

For those who need a Java-enabled browser for a specific use case, there is e.g. palemoon/palemoon-bin available in the palemoon overlay, which has long-term support for NPAPI and thus Java plugins up to JDK 8[3].

USE flags for use with Java

Configurando as USE flags

Para mais informações referentes a USE flags, acesse o capítulo USE flags do Manual Gentoo.

USE flags

  • The java flag adds support for Java in a variety of programs;
  • The nsplugin flag adds support for Mozilla-like browsers (including Firefox). This is needed for viewing Java applets in a Mozilla-like browser;

Following USE flags go in JAVA_PKG_IUSE, see Gentoo Java USE flags for details and other specific USE flags of Java:

  • The source flag installs a zip of the source code of a package. This is traditionally used for IDEs to 'attach' source to the libraries that are being use;
  • For Java packages, the doc flag will build API documentation using javadoc.

Troubleshooting

Minecraft launcher errors

  • A specific error in which minecraft-launcher crashed after a few seconds, throwing "Alarm" and "SaveToBuffer failed" error was solved by setting the USE flag threads for net-misc/curl.
  • When executing minecraft-launcher the following error was produced:
user $./minecraft-launcher
[0229/184549.183275:ERROR:sandbox_linux.cc(346)] InitializeSandbox() called with multiple threads in process gpu-process.

This was solved by executing minecraft-launcher with the following option:

user $MESA_GLSL_CACHE_DISABLE=true ./minecraft-launcher

Veja também

Recursos externos

Mais informações podem ser encontradas offline:

  • man java-config
  • java-config --help

Para sugestões ou dúvidas em relação a esse document, por favor envie um e-mail ao time Java Gentoo: java@gentoo.org

Referências

  1. JDK 9 and the Java Plugin, java.com. Retrieved on November 30, 2018
  2. How do I enable Java in my web browser?, java.com. Retrieved on November 30, 2018
  3. Pale Moon future roadmap, palemoon.org. Retrieved on June 28, 2019

This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Joshua Nichols, Karl Trygve Kalleberg, nightmorph
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.