ubuntu源码安装jdk8

最近学习java,想起来没有在Ubuntu上使用过

因此想安装下环境,并在Ubuntu上试用MPXJ读取mpp文件

1.安装

下载jdk8

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

新建目录

mkdir  /usr/lib/jvm

解压

tar -zxvf jdk-8u211-linux-x64.tar.gz -C /usr/lib/jvm

修改环境变量

vim ~/.bashrc

追加

#set oracle jdk environment
export JAVA_HOME=/usr/lib/jvm/jdk1..0_211
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

使生效

 source ~/.bashrc

2.测试

(1)是否安装成功

ubuntu源码安装jdk8

(2)Hello.java

public class Hello {
private Integer aa = ;
public String ss = "sss";
public static void main(String[] args) {
System.out.println("Hello Java");
}
}
 javac Hello.java

ubuntu源码安装jdk8

java Hello

ubuntu源码安装jdk8

javap Hello

ubuntu源码安装jdk8

3.用MPXJ读取mpp文件

在http://www.mpxj.org/官网MPXJ in Java,进入下载页

添加MPXJ的包

在/usr/lib/jvm/jdk1.8.0_211/jre/lib/ext下添加下面的jar包(我的安装目录在/usr/lib/jvm/jdk1.8.0_211下)

mpxj.jar
commons-collections4-4.1.jar
poi-3.17.jar
rtfparserkit-1.10..jar

在/www/javatest下添加mpxjtest.java

 import net.sf.mpxj.mpp.*;
import net.sf.mpxj.MPXJException;
import net.sf.mpxj.Resource;
import net.sf.mpxj.ResourceAssignment;
import net.sf.mpxj.Task;
import net.sf.mpxj.ProjectFile;
import java.util.List;
import java.io.*;
public class mpxjtest {
public static void main(String[] args) throws MPXJException {
File file = new File("/www/javatest/aa.mpp");
MPPReader mppRead = new MPPReader();
ProjectFile pf = mppRead.read(file);
List tasks = pf.getAllTasks();
mpxjtest mt = new mpxjtest();
System.out.println("总任务数: " + tasks.size());
System.out.println("ID|任务名|资源|开始时间|结束时间|完成百分比");
for (int i = ; i < tasks.size(); i++) {
System.out.println(((Task) tasks.get(i)).getUniqueID() + "|" + ((Task) tasks.get(i)).getName());
}
}
public String getResource(Task task) {
StringBuffer buf = new StringBuffer();
List assignments = task.getResourceAssignments();
for (int i = ; i < assignments.size(); i++) {
ResourceAssignment assignment = (ResourceAssignment) assignments .get(i);
Resource resource = assignment.getResource();
if (resource != null) {
buf.append(resource.getName()).append(" ");
}
}
return buf.toString();
}
}

运行

javac mpxjtest.java
java mpxjtest

结果

ubuntu源码安装jdk8

说明:

  还可以通过ppa(源) 方式安装

add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer
上一篇:C语言第七次博客作业--一二维数组


下一篇:可用免费asp.net空间