Запустить jar файл linux

How to run .jar file on unix?

You must be trying to launch a jar compiled with JDK6, with a local java1.5.

 javac -source 1.5 -target 1.5 -bootclasspath /path/to/jre1.5/lib/rt.jar 

to check if you can generate 1.5 bytecode compatible.

Have you tried using a newer version of Java on your Unix system?

If you control the jar file, could you target Java 1.5 when it’s compiled?

UnsupportedVersionError means that you have compiled the Java source code with a newer version of Java than what you’re trying to run it with. Java is downwards compatible (newer versions of Java can run Java programs compiled with older versions), but not upwards compatible (older versions of Java cannot run Java programs compiled with newer versions).

You say you’re using Java 5 on Unix. Did you compile it using Java 6 on Windows? Then it’s obviously not going to work.

  • Compile your source code using Java 5 on Windows (the safest option)
  • Use the compiler flags: -source 1.5 -target 1.5 while you compile (this will not protect you against using Java 6-only classes from the standard library, so this is not a full guarantee that your program will run without errors on Java 5)
  • Upgrade to Java 6 on Unix

Recompile your application with Java 5 on your Windows machine.

(Java 6 generates Java 6 compatible byte code by default to use new facilities. The easiest for you is to install a Java 5 JDK and use it to recompile your application)

  • Check that JDK or JRE is installed. Install if it is not.
  • set JAVA_HOME= # JDK/JRE home directory
  • $JAVA_HOME/bin/java -jar file.jar

You should also keep in mind that JVM are not forward compatible, so if you’ve made a jar-file using JDK 1.6, it won’t work with JDK 1.5!

In this case you may either:

  • install JDK 1.6 to Unix
  • recompile the jar with -target 1.5 flag (but you may get any sort of errors due to API incompatibilities, so the first way is much better)

I faced the same problem. This is because the runtime and compile time JDK versions are different. Make the jar through eclipse after changing the java compiler version. The following link helped me.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.13.43531

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

🐧 Как запустить JAR-файл на Linux

JAR- это файлы, которые были спрограмированны и скомпилированы с использованием языка программирования Java.

Для того чтобы запустить эти файлы в системе Linux, необходимо сначала установить программное обеспечение Java Runtime Environment (JRE).

Это просто пакет программного обеспечения, который позволяет системе понимать файлы JAR и, следовательно, дает ей возможность открывать и запускать их.

Читайте также:  Vmware horizon client install linux

Обычно пакет JRE не установлен в большинстве дистрибутивов Linux по умолчанию, поэтому мы должны сначала установить Java, а затем открыть файл(ы) JAR.

В этом руководстве мы покажем вам, как установить Java Runtime Environment на все основные дистрибутивы Linux.

Это позволит вам открывать JAR-файлы независимо от того, какой дистрибутив Linux вы используете.

Затем мы будем использовать установленное программное обеспечение для открытия файлов JAR в Linux как через командную строку, так и через графический интерфейс.

Как установить JRE на все основные дистрибутивы Linux

Первое, что нам нужно сделать, это установить Java Runtime Environment, чтобы мы могли открывать файлы JAR.

Вы можете использовать соответствующую команду ниже, чтобы установить Java JRE с помощью менеджера пакетов вашей системы.

Чтобы установить Java JRE на Ubuntu, Debian, Linux Mint, MX Linux и Kali Linux:

$ sudo apt update $ sudo apt install default-jre

Чтобы установить Java JRE на Fedora, CentOS, Alma Linux, RockyLinux и Red Hat:

$ sudo dnf install java-latest-openjdk

Чтобы установить Java JRE на Arch Linux и Manjaro:

Запуск JAR-файла из командной строки

Запуск JAR-файла из командной строки очень прост.

Мы можем использовать следующий синтаксис:

Если JAR-файл имеет компонент GUI, он будет запущен на вашем экране.

В противном случае текст будет выведен на терминал.

Заключение

В этом руководстве мы рассмотрели, как запустить JAR-файл в системе Linux.

Единственная хитрость здесь заключается в том, что сначала нам нужно установить среду выполнения Java, которая имеет различные инструкции в зависимости от используемого дистрибутива Linux.

После установки программы JRE мы можем запускать JAR-файлы как из командной строки, так и из графического интерфейса.

Источник

Запустить jar файл linux

  • How to maintain polyglot persistence for microservices Managing microservice data may be difficult without polyglot persistence in place. Examine how the strategy works, its challenges.
  • Top developer relations trends for building stronger teams Learn about enterprise trends for optimizing software engineering practices, including developer relations, API use, community .
  • 5 noteworthy challenges of automotive software development Modern cars are loaded with technology, but creating in-vehicle applications isn’t always a cakewalk. Here are five unique .
  • The potential of ChatGPT for software testing ChatGPT can help software testers write tests and plan coverage. How can teams anticipate both AI’s future testing capabilities .
  • Retail companies gain DORA metrics ROI from specialist tools DORA metrics and other measures of engineering efficiency are popping up in add-ons to existing DevOps tools. But third-party .
  • Scrum master certification exam questions and answers Are you ready for the Scrum master certification exam? Test yourself on these 10 tough Scrum master exam questions and answers.
  • How to create and manage Amazon EBS snapshots via AWS CLI EBS snapshots are an essential part of any data backup and recovery strategy in EC2-based deployments. Become familiar with how .
  • Prices for cloud infrastructure soar 30% Tough macroeconomic conditions as well as high average selling prices for cloud computing and storage servers have forced .
  • Deploy a low-latency app with AWS Local Zones in 5 steps Once you decide AWS Local Zones are right for your application, it’s time for deployment. Follow along in this step-by-step video.
  • Microsoft: Government agencies breached in email attacks While Microsoft mitigated the attacks and found no evidence of further access beyond the email accounts, the Outlook breaches .
  • The history, evolution and current state of SIEM SIEM met the need for a security tool that could pinpoint threats in real time. But new threats mean that the next evolution of .
  • Chainalysis observes sharp rise in ransomware payments The rise in total ransomware payments so far this year is a reversal of the decline Chainalysis saw in 2022, when payments fell .
  • AWS Control Tower aims to simplify multi-account management Many organizations struggle to manage their vast collection of AWS accounts, but Control Tower can help. The service automates .
  • Break down the Amazon EKS pricing model There are several important variables within the Amazon EKS pricing model. Dig into the numbers to ensure you deploy the service .
  • Compare EKS vs. self-managed Kubernetes on AWS AWS users face a choice when deploying Kubernetes: run it themselves on EC2 or let Amazon do the heavy lifting with EKS. See .
Читайте также:  Linux and windows 2000

Источник

How can I execute a .jar file from the terminal

I am trying to execute a Minecraft.jar file

I know that to execute a file, I use the . command, then the file name with a space between them. But I’m trying to execute a .jar file using the . and it does not work. I went into the properties and marked it as executable and made it run with Java. Is there a way to execute a file with Java in the Bash Terminal? I am trying to execute the Minecraft.jar file.

Hello and welcome, jaorizabal. I slightly corrected your question. Maybe you can install a spell checker for your browser, to improve the next question yourself. Another hint: For text issues, you may mark text with your mouse in the terminal, and then paste it into the edit field of your browser (and elsewhere) with a middle click on the scroll wheel. Then you can layout your code with the buttons at the edit field. This is much faster than taking a screen shot, and uploading it.

9 Answers 9

The . syntax can only be used to run (by «sourcing») shell scripts.

You’ll need to use the java command to run a .jar file:

If you don’t have java installed, you can fix that by installing the default-jre ¹ package. You can see if you already have java installed by running in a terminal:

[1]: This will install the default openjdk Java runtime. You can use openjdk-8-jre , or openjdk-7-jre , or openjdk-6-jre instead, if you prefer — whichever is available on your version of Ubuntu.

Linux is perfectly capable of running a foreign binary, like a JAR file. This is how Wine works, for example. To run JAR files as executable do the following in a console

sudo apt-get install binfmt-support 

Cd to your JAR file and change it to executable (you can also do this through file properties in Nautilus)

Run your jar file just as if it was any other binary executable or shell script

Note: Be sure you have binfmt_misc linux kernel module loaded. If you use your custom compiled kernel without this module, binfmt-support won’t work.

Thanks! This is exactly what I was looking for. It’s better than using java -jar because it doesn’t require the host program to know that it is a java program, and it’s better than using a script because you don’t have to worry about passing through STDIN and OUT.

Читайте также:  Better fonts on linux

If it is an executable jar, then

Not all jar-Archives contain an executable class, declared to be started in the Manifest file, but if there is, this will work.

Btw.: You don’t start most programs from the shell with the dot. The dot is a shortcut for source , and it only works in the bash and some other shells, to include a script in the scope of the current session.

A compiled binary xybin is simply started with its name if it is in the path:

or, with its absolute path:

or with its relative path:

or if you happen to be in the directory of the file, with this relative path:

The file has to be marked executable for you (see: chmod). All of the above is true for shellscripts too, but they often have an extension .sh, and you can start a shellscript by invoking the interpreter, and then it needn’t be marked executable:

If you don’t want to start a new bash, you can use source, and you do so, to consume function definitions, aliases and variable settings.

You might as well want to make a nice entry for the application in Unity. execute the following commands:

gedit ~/.local/share/applications/minecraft.desktop 

In the window that pops up, copy and paste the following:

[Desktop Entry] Type=Application Name=Minecraft Comment=Click here to play Minecraft Exec=java -jar /path/to/minecraft.jar Icon=/path/to/minecraft/icon.png Terminal=false Categories=Game; 

You might need to log out and back in to see the effects. 🙂 Also you need to search the internet for a nice lookin Minecraft icon since they don’t provide one with the download..

  1. Open a command prompt with CTRL + ALT + T
  2. Go to your «.jar» file directory. If your Ubuntu version / flavour supports it, you should be able to right click on your «.jar» file’s directory and click «Open in Terminal»
  3. Type the following command:

This way your «.jar» file will execute.

Install jarwrapper. After that (and by adding the executable bit) you can start the jar file just by entering the jarfile name.

sudo apt-get install jarwrapper 

This works by using binfmt to add support for a new binary format to the kernel.

 java -jar /home/username/.minecraft/launcher.jar 

New answer to an old question

Executing a jar file using the regular syntax ./app.jar (instead of java -jar ), is easy to achieve, as explained here: how to create executable jars.

Basically, JAR is a variant of ZIP, which allows random bytes to be pre/appended to the JAR without corrupting it. This means it is possible to prepend a launcher script at the beginning of the jar to make it «executable».

Here is a simple example of turning a «normal» jar into an executable one:

# Append a basic launcher script to the jar cat \ <(echo '#!/bin/sh')\ <(echo 'exec java -jar $0 "$@"')\ <(echo 'exit 0')\ original.jar >executable.jar # Make the new jar executable chmod +x executable.jar 

With this, you can now run ./executable.jar instead of java -jar original.jar . This works on all unix like systems including Linux, MacOS, Cygwin, and Windows Linux subsystem.

Источник

Оцените статью
Adblock
detector