javac 编译java源文件时,提示 package does not exist 的错误

Test.java

import java.security.MessageDigest;
import org.apache.commons.codec.binary.Hex; public class Test{
public static void main(String args[]){
boolean isAlarmed = true;
boolean aa = isAlarmed || false;
String queryTimestamp = "1970-01-01T00:00:00+0000";
System.out.println(queryTimestamp.getBytes());
try{
MessageDigest md5 = MessageDigest.getInstance("MD5");
System.out.println(md5.digest("stringtodigest".getBytes())); byte[] value = "stringtodigest".getBytes();
md5.update(value);
byte[] digest = md5.digest();
System.out.println(new String(Hex.encodeHex(digest))); System.out.println(md5.digest("stringtodigest".getBytes()));
System.out.println(md5.digest("stringtodigest".getBytes()));
}catch(Exception e){ }
}
}

  javac Test.java编译的时候报错!

解决办法:

  1. 到mvn repository(http://mvnrepository.com/artifact/commons-codec/commons-codec/1.7)上面吧缺少的 jar 包下载下来,

  2. 然后给 CLASSPATH 环境变量在添加一下这个jar 包所在的路径,就可以了。

---------------------------------------------------------------------------------------

参考:https://www.linuxquestions.org/questions/programming-9/javac-compiling-error-mising-package-669775/

javac compiling error ( mising package)

First i have to say I am very new to java. I downloaded java codes from the Internet and try to compile them using javac. I got following error,
Code:

  

C:\temp\javacrypt>"C:\Program Files\Java\jdk1.6.0_06\bin\javac" RSAExample.java
.\BaseCrypto.java:1: package org.apache.commons.codec does not exist
import org.apache.commons.codec.DecoderException;
^
.\BaseCrypto.java:2: package org.apache.commons.codec.binary does not exist
import org.apache.commons.codec.binary.Hex;
^
.\BaseCrypto.java:26: cannot find symbol
symbol : class DecoderException
location: class BaseCrypto
public static byte[] asByte(String hexString) throws DecoderException {
^
.\BaseCrypto.java:16: cannot find symbol
symbol : variable Hex
location: class BaseCrypto
return new String(Hex.encodeHex(buf));
^
.\BaseCrypto.java:27: cannot find symbol
symbol : variable Hex
location: class BaseCrypto
return Hex.decodeHex(hexString.toCharArray());
^
5 errors

  I guess i just missed some packages like "org.apache.commons.codec.*",
  and that package is not part of standard jdk, right?

  How do i get those package? I also have netbean and eclipse, but I haven't tried to use them yet.

  -----------------

When you get the package, which is probably a .jar file, add that .jar file to your classpath (environment variable).

EDIT: Specifically, here.

EDIT: I believe on Windows it's something like...

SET CLASSPATH=%CLASSPATH%;C:\path\to\jar\jarfile.jar

----------------------

I downloaded the jar file suggested by elprawn, and it work great!! thank you so much.
I am curious about the suggestion from jay73. Is the package management the software like "yum" or "apt-get", right? What keyword should use to search for it?

----------------------

On a system that uses apt, you can use 
aptitude search commons
and you'should get a list of the available commons libraries.On ubuntu:

jurgen@Selena:~$ aptitude search commons
i libcommons-attributes-java - adds C#/.Net-style attributes to Java code
i A libcommons-beanutils-java - utility for manipulating JavaBeans
i libcommons-beanutils-java-doc - Javadoc API for libcommons-beanutils-java
i A libcommons-cli-java - API for working with the command line argu
i A libcommons-codec-java - encoder and decoders such as Base64 and he
i A libcommons-collections-java - A set of abstract data type interfaces and
i A libcommons-collections3-java - A set of abstract data type interfaces and
i libcommons-collections3-java-do - Documentation for libcommons-collections3-
i libcommons-configuration-java - Java based library providing a generic con
p libcommons-csv-java - a Java library for working with csv (comma
p libcommons-csv-java-doc - documentation for libcommons-csv-java
i A libcommons-daemon-java - library to launch Java applications as dae
i A libcommons-dbcp-java - Database Connection Pooling Services
i A libcommons-digester-java - Rule based XML Java object mapping tool
p libcommons-discovery-java - locates classes that implement a given Jav
i A libcommons-el-java - Implementation of the JSP2.0 Expression La
i libcommons-fileupload-java - File upload capability to your servlets an
i libcommons-httpclient-java - A Java(TM) library for creating HTTP clien
i libcommons-httpclient-java-doc - Documentation for libcommons-httpclient-ja
i libcommons-io-java - Common useful IO related classes
i libcommons-io-java-doc - Common useful IO related classes - documen
p libcommons-jexl-java - expression language engine
p libcommons-jxpath-java - manipulate javabean using XPath syntax
p libcommons-jxpath-java-doc - Javadoc API for libcommons-jxpath-java
i A libcommons-lang-java - Extension of the java.lang package
i A libcommons-launcher-java - cross platform java application launcher
i A libcommons-logging-java - commmon wrapper interface for several logg
i A libcommons-modeler-java - convenience library to use Java Management
i libcommons-modeler-java-doc - documentation and examples for Commons Mod
i libcommons-net-java - internet protocol suite Java library
p libcommons-openpgp-java - a common and simple interface for generati
p libcommons-openpgp-java-doc - a common and simple interface for generati
i A libcommons-pool-java - pooling implementation for Java objects
i libcommons-validator-java - ease and speed development and maintenance
p libgettext-commons-java - Java classes for internationalization (i18
p libhibernate-commons-annotation - Hibernate Commons Annotations
p libws-commons-util-java - Common utilities from the Apache Web Servi
p libxml-commons-resolver1.1-java - XML entity and URI resolver library
p libxml-commons-resolver1.1-java - XML entity and URI resolver library -- doc
p libxml-commons-resolver1.1-java - XML entity and URI resolver library -- nat
i libxmlgraphics-commons-java - reusable components used by Batik and FOP

  

javac compiling error ( mising package)的更多相关文章

  1. dpkg: error processing package libraspberrypi-doc (--configure): package is in a very bad inconsistent state;

    dpkg: error processing package libraspberrypi-doc (--configure): package is in a very bad inconsiste ...

  2. error processing package oracle-java8-installer问题解决

    ubuntu通过ppa源安装jdk时遇到如下问题: download failedOracle JDK 8 is NOT installed.dpkg: error processing packag ...

  3. Ubuntu14.04.3,apt-get出现dpkg: error processing package xxx (--configure)和cups-daemon错误的解决方案

    Ubuntu14.04.3,使用apt-get安装软件的时候,报个莫名其妙的错误: dpkg: error processing package xxx (--configure): balabala ...

  4. dpkg: error processing package bluez (--configure) 解决方法【转】

    转自:http://blog.csdn.net/heray1990/article/details/47803541 在 Ubuntu 执行 sudo apt-get upgrade 时,出现了如下的 ...

  5. dpkg: error processing package XXX (--configure) 解决方法 (ubuntu右上角红色警告)

    在 Ubuntu 执行 sudo apt-get upgrade 时,出现了如下的报错: Setting up bluez (4.101-0ubuntu13.1) ... reload: Job is ...

  6. ubuntu 下python出现pkg: error processing package *python* 解决之道

    1.linux有些自带程序很多是python写的,自带的python2也最好不要升级,不然会有很多问题 2.如果遇到 pkg: error processing package *python* (- ...

  7. Java直接用javac来编译带package的类

    在没有package语句的java类, 我们可以直接使用: javac Test.java 就可以了, 如果Test.java中包含package语句,如:package abc; 编译后,是要求Te ...

  8. centos运行netcore error:package: ‘Microsoft.AspNetCore.Antiforgery‘, version: ‘2.0.3‘

    Error: An assembly specified in the application dependencies manifest (*.*.deps.json) was not found: ...

  9. 关于编译(javac),import,package的再理解

    1.若我们在A.java中用到了类B,当我们仅仅用 javac A.java 编译A时,编译器也会去寻找B,若类B依然是源文件,也会自动编译它.在使用javac和java命令时,有一个参数选项 -ve ...

随机推荐

  1. Coursera公开课-Machine_learing:编程作业4

    编程作业: Neural Network Learning 源码上传到gitlab. 对于神经网络的理解也都在源码注释里面了,感兴趣可以看看.

  2. c/c++ 参数传递 - 数组

    对于函数参数中的数组类型:传递的是数组地址,可以理解成传递的是对数组的引用.不是值传递,这是由C/C++函数实现机制决定的.一下三种函数生命完全等价: void func(int array[10]) ...

  3. Task.Run 和 Task.Factory.StartNew

    在.Net 4中,Task.Factory.StartNew是启动一个新Task的首选方法.它有很多重载方法,使它在具体使用当中可以非常灵活,通过设置可选参数,可以传递任意状态,取消任务继续执行,甚至 ...

  4. GitLab Runner and CICD

    # Linux x86-64 sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaw ...

  5. Oracle 递归的写法(start with) 以及where条件作用域

    先转一个讲Oracle递归讲得非常透彻的文章: http://blog.csdn.net/weiwenhp/article/details/8218091 前言:嗯,这也是一个前人挖坑,后人来填的故事 ...

  6. JVM 内存区域划分

    一.运行时数据区包括哪几部分? 根据<Java虚拟机规范>的规定,运行时数据区通常包括这几个部分:程序计数器(Program Counter Register).Java栈(VM Stac ...

  7. [ NOIP 1998 ] TG

    \(\\\) \(\#A\) 车站 火车从第\(1\)站开出,上车的人数为\(a\),然后到达第\(2\)站,在第\(2\)站有人上.下车,但上.下车的人数相同,因此在第\(2\)站开出时(即在到达第 ...

  8. 深拷贝js

    JSON 最简单的一个 let obj = {} let newObj = JSON.parse(JSON.stringify(obj)) 弊端:这种方法无法拷贝function函数,undefine ...

  9. 1、Xamarin 环境准备

    一.安装环境 1.安装VS2017 2.安装Xamarin扩展包 3.安装NDK 工具栏中,一个为AVD(模拟器管理)一个为NDK(管理Andoid SDK) 3.1 先打开NDK,在Tools\Op ...

  10. mysql异地备份方案经验总结

    Mysql 数据库异地备份脚本 实验环境:关闭防火墙不然不能授权登录 Mysql-server:192.168.30.25 Mysql-client:  192.168.30.24 实验要求:对mys ...