简体   繁体   English

Ubuntu 14.04,无法将类打包到“ jar”文件中

[英]Ubuntu 14.04,unable to package classes into 'jar' file

I am learing Java from'HeadFirst Java' My current setup is Ubuntu 14.04 我正在从“ HeadFirst Java”中学习Java我的当前设置是Ubuntu 14.04

Oracle JDK 1.8 is installed and set as defaut ,Oracle Java is also set as default 已安装Oracle JDK 1.8并将其设置为defaut,还将Oracle Java设置为默认值

I have Many Tools such as AndroidStudio and Eclipse Perfectly working and dont want to break them,by changing to Open JDK 我有很多工具,例如AndroidStudio和Eclipse,它们可以完美运行,并且不想更改它们,只需改用Open JDK

My Problem is 我的问题是

I am tyring an exercise on Java Packaging and Deployement 我正在进行有关Java打包和部署的练习

Directory Structure :MYProject:->Classes,Source 目录结构:MYProject:->类,源

Source:->MyBall.Java Classes:MyPanel.class,MyBall.class etc,manifest.text(contains Min-Class:MyBall) 来源:-> MyBall.Java类:MyPanel.class,MyBall.class等,清单文本(包含Min-Class:MyBall)

With Present Working Directory as 'MyProject' I want to make the Source Folder as a JAR 使用当前工作目录为“ MyProject”,我想将源文件夹制作为JAR

The Book says : 该书说:

jar -cvmf manifest.txt app1 .jar *.class

should do the trick 应该做到的

But the output i get is 但是我得到的输出是

The program 'jar' can be found in the following packages:

 * default-jdk
 * fastjar
 * gcj-4.8-jdk
 * openjdk-7-jdk
 * gcj-4.6-jdk
 * openjdk-6-jdk

Here are the versions: 这些是版本:

java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

javac 1.8.0_11

I find this to be relevant https://stackoverflow.com/a/18166639/3725998 But dont know how to change variable etc , Not a Linux Expert , So Please Guide me! 我发现这是相关的https://stackoverflow.com/a/18166639/3725998但不知道如何更改变量等,不是Linux专家,所以请指导我!

What you need to do is tell the operating system where the jar program lives. 您需要做的是告诉操作系统jar程序所在的位置。 In your home directory, you will most likely have a file called .bashrc . 在您的主目录中,您很可能会有一个名为.bashrc的文件。 Go to the end of the file and add the following: 转到文件末尾并添加以下内容:

export JAVA_HOME=<path to your JDK install e.g. /opt/jdk>
export PATH=$JAVA_HOME/bin:$PATH

This sets your JAVA_HOME environment variable - commonly used by Java-based applications such as Tomcat. 这将设置您的JAVA_HOME环境变量-通常由基于Java的应用程序(例如Tomcat)使用。 It then prepends that directory to your PATH variable. 然后,它将该目录添加到您的PATH变量中。 The operating system understands PATH as a list of the parent directories of executable files. 操作系统将PATH理解为可执行文件的父目录的列表。

When you have changed your file, type the following at the command prompt to re-load your shell profile: 更改文件后,在命令提示符处键入以下内容以重新加载Shell配置文件:

. .bashrc

In Ubuntu 14.04 edit /etc/environment to add the JAVA_HOME 在Ubuntu 14.04中,编辑/ etc / environment以添加JAVA_HOME

sudo gedit /etc/environment

Add the line 添加行

JAVA_HOME="/usr/lib/jvm/jdk-[version]"

Reload the file 重新载入档案

source /etc/environment

First of all, there should not be an space between app1 and .jar . 首先, app1.jar之间不应有空格。 So, if Java is installed correctly, this should do the trick. 因此,如果Java安装正确,就可以解决问题。

jar -cvmf manifest.txt app1.jar *.class

However, I don't think that's the cause of your error. 但是,我不认为这是导致您出错的原因。

You can try updating to the latest version of Oracle Java 8. I find this guide easy to follow, even if you don't have a lot of experience with Linux. 您可以尝试将其更新到最新版本的Oracle Java8。即使您对Linux没有太多的经验,我也很容易遵循本指南。

http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM