java 环境配置 maven 环境配置

1、windows 下Java 环境的安装和配置:

下载jdk并安装

配置环境变量:

(1) 新建JAVA_HOME环境变量,赋值为JDK的安装目录:

(2) 新建CLASSPATH环境变量,赋值为.;%JAVA_HOME%libdt.jar;%JAVA_HOME%lib ools.jar;

(3) 在PATH环境变量中追加Java环境变量:

CMD运行如下代码,测试我们的安装和配置:

java -version

java

javac

参考:http://www.cnblogs.com/eagle6688/p/7873477.html

2、maven环境配置,博主写的很详细,感谢。

https://www.cnblogs.com/eagle6688/p/7838224.html

配置好maven之后,创建maven项目:

1) file -- new --maven project -- 选择项目存放位置 --next -- 设置group id 和项目名称 --- finish

2)配置 pom.xml  即 项目所需要的依赖包,可能存在冲突的依赖,可以有两种方法,一种是删除原有的依赖包重新生成,另一种是修改默认依赖包存放路径,然后重新生成。 另外,有时候可能是项目的依赖没有更细 ,选中项目--右键 maven -- update 即可更新,红色小叉消失

3) window --- preference -- maven --  installation 可以配置安装 maven的路径, usersetting 可以设置maven的 settings.xml  及依赖包的存放位置

详情 参考链接 https://www.cnblogs.com/eagle6688/p/7838224.html

3、IDE:

Eclipse安装

4、jar包

右键项目 -- export --- Java -- jar file  -- 设置路径和jar包名称即可  【- export --- Java -- Runable jar file -- 要变为jar包的项目 -- 设置路径和jar包名称】

另外,对于带有依赖的jar包:

右键项目 -- Maven --  Run as  -- maven bulid  ---Goals (package) --- RUN  打包后默认保存在项目的target 路径下面;

maven 的pom.xml 文件实例,需要打包依赖时的关键配置:

<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>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.2</version>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
					<encoding>${project.build.sourceEncoding}</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.7</version>
				<configuration>
					<encoding>${java.encoding}</encoding>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
					<archive>
						<manifest>
							<mainClass></mainClass>
						</manifest>
					</archive>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id> <!-- this is used for inheritance merges -->
						<phase>package</phase> <!-- bind to the packaging phase -->
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>


</project>

  

5、在shell 文件中包含主类和 jar包  以及传入的参数

--class spark.bdp.demo.example.App
bdp_jar_test.jar $1 $2 $ 3

原文地址:https://www.cnblogs.com/Allen-rg/p/9397866.html