简体   繁体   中英

Ubuntu 14.04,unable to package classes into 'jar' file

I am learing Java from'HeadFirst Java' My current setup is Ubuntu 14.04

Oracle JDK 1.8 is installed and set as defaut ,Oracle Java is also set as default

I have Many Tools such as AndroidStudio and Eclipse Perfectly working and dont want to break them,by changing to Open JDK

My Problem is

I am tyring an exercise on Java Packaging and Deployement

Directory Structure :MYProject:->Classes,Source

Source:->MyBall.Java Classes:MyPanel.class,MyBall.class etc,manifest.text(contains Min-Class:MyBall)

With Present Working Directory as 'MyProject' I want to make the Source Folder as a 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!

What you need to do is tell the operating system where the jar program lives. In your home directory, you will most likely have a file called .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. It then prepends that directory to your PATH variable. The operating system understands PATH as a list of the parent directories of executable files.

When you have changed your file, type the following at the command prompt to re-load your shell profile:

. .bashrc

In Ubuntu 14.04 edit /etc/environment to add the 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 . So, if Java is installed correctly, this should do the trick.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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