docker中,jdk用镜像 怎么配置环境变量
2个回答
2016-03-13 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
docker中,jdk用镜像配置环境变量的方法如下:
一、安装 JDK
1、首先,解压 JDK 程序包:
tar -zxf /mnt/software/jdk-7u67-linux-x64.tar.gz -C .
2、重命名 JDK 目录:
mv jdk1.7.0_67/ jdk/
二谨团樱、设置环境祥丛变量
首先,编辑.bashrc文件
vi ~/.bashrc
然后,在该文件末尾添加如下配置:
export JAVA_HOME=/opt/jdk
export PATH=$PATH:$JAVA_HOME
最后,需要使用source命令,让环境变量生效或闷:
source ~/.bashrc
一、安装 JDK
1、首先,解压 JDK 程序包:
tar -zxf /mnt/software/jdk-7u67-linux-x64.tar.gz -C .
2、重命名 JDK 目录:
mv jdk1.7.0_67/ jdk/
二谨团樱、设置环境祥丛变量
首先,编辑.bashrc文件
vi ~/.bashrc
然后,在该文件末尾添加如下配置:
export JAVA_HOME=/opt/jdk
export PATH=$PATH:$JAVA_HOME
最后,需要使用source命令,让环境变量生效或闷:
source ~/.bashrc
展开全部
使用Docker 进行Java 开发步骤:
1、准备工作
现在最流行的是选择Spark,它是一个基于Java 8的极小的框架。Spark使用Maven作为构建工具。
2、源代码和配置文件
在这个例子中你要增加三个文件:
Maven的态埋配置文件: pom.xml
一个Java类:Hello.java
一个Dockerfile
例子:
hello.java:
package sparkexample;
import static spark.Spark.get;
public class Hello {
public static void main(String[] args) {
get("/", (req, res) -> {
return "hello from sparkjava.com";
});
}
}
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hellodocker</groupId>
<artifactId>hellodocker</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<橡租groupId>org.apache.maven.plugins</groupId>
<帆如蚂artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>sparkexample</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>sparkexample.Hello</mainClass>
<classpathPrefix>dependency-jars/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>attached</goal>
</goals>
<phase>package</phase>
<configuration>
<finalName>sparkexample</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>sparkexample.Hello</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Dockerfile:
FROM java:8
# Install maven
RUN apt-get update
RUN apt-get install -y maven
WORKDIR /code
# Prepare by downloading dependencies
ADD pom.xml /code/pom.xml
RUN ["mvn", "dependency:resolve"]
RUN ["mvn", "verify"]
# Adding source, compile and package into a fat jar
ADD src /code/src
RUN ["mvn", "package"]
EXPOSE 4567
CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "target/sparkexample-jar-with-dependencies.jar"]
1、准备工作
现在最流行的是选择Spark,它是一个基于Java 8的极小的框架。Spark使用Maven作为构建工具。
2、源代码和配置文件
在这个例子中你要增加三个文件:
Maven的态埋配置文件: pom.xml
一个Java类:Hello.java
一个Dockerfile
例子:
hello.java:
package sparkexample;
import static spark.Spark.get;
public class Hello {
public static void main(String[] args) {
get("/", (req, res) -> {
return "hello from sparkjava.com";
});
}
}
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hellodocker</groupId>
<artifactId>hellodocker</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<橡租groupId>org.apache.maven.plugins</groupId>
<帆如蚂artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>sparkexample</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>sparkexample.Hello</mainClass>
<classpathPrefix>dependency-jars/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>attached</goal>
</goals>
<phase>package</phase>
<configuration>
<finalName>sparkexample</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>sparkexample.Hello</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Dockerfile:
FROM java:8
# Install maven
RUN apt-get update
RUN apt-get install -y maven
WORKDIR /code
# Prepare by downloading dependencies
ADD pom.xml /code/pom.xml
RUN ["mvn", "dependency:resolve"]
RUN ["mvn", "verify"]
# Adding source, compile and package into a fat jar
ADD src /code/src
RUN ["mvn", "package"]
EXPOSE 4567
CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "target/sparkexample-jar-with-dependencies.jar"]
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |