# [Java] 開發環境 ###### tags: `Java` `Maven` `JDK` ## JDK 安裝與環境變數設定 1. 下載 JDK * [Oracle JDK](https://www.oracle.com/java/technologies/downloads/#java17) * [OpenJDK](https://jdk.java.net/java-se-ri/17) 2. 安裝 JDK * 將檔案解壓縮至指定的路徑位置 3. 新增/修改環境變數 * JAVA_HOME `C:\Program Files\Java\jdk1.7.0_51` (JDK安裝的路徑) * PATH `%JAVA_HOME%\bin` (需移至最上層) * classpath `.;` 4. 驗證是否安裝成功 * 輸入 `java –version` 查看當前版本 * 環境變數設定查看 `javac` ## Maven 安裝與環境變數設定 1. 下載 Maven * [Apache Maven 3.8.6](https://maven.apache.org/download.cgi) (選擇 Binary zip archive--> Link) 2. 安裝 Maven * 將檔案解壓縮至指定的路徑位置 3. 新增、修改環境變數 * MAVEN_PATH `C:\Program Files\apache-maven-3.8.6\bin` * PATH `%MAVEN_PATH%\bin` 4. 驗證是否安裝成功 * 輸入 `mvn -v` 查看當前版本 ### 打包 jar 1. 啟動專案 2. 進入要打包的專案目錄內 3. 打包 ``` mvn clean package ``` 3. 會放在目標目錄的 `target` 資料夾內 資料來源: [執行maven的示範](https://vocus.cc/article/62e39263fd897800018c96ec) [Apache Maven 建置](https://blog.miniasp.com/post/2022/09/06/Understanding-Apache-Maven-build-tool) #### 打包失敗 ```=cmd! [ERROR] Failures: [ERROR] RepoTests.testCreateRoles:80 expected: 3 but was: 6 [ERROR] Errors: [ERROR] RepoTests.testCreateUser:46 ? DataIntegrityViolation could not execute stateme... [INFO] [ERROR] Tests run: 3, Failures: 1, Errors: 1, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 15.999 s [INFO] Finished at: 2022-12-08T00:20:35+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project Love-And-Share-Demo: There are test failures. [ERROR] [ERROR] Please refer to C:\workspace\demo\target\surefire-reports for the individual test results. [ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException ``` 需於專案 `pom.xml` 加入以下配置 ```=xml! <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> ``` ### jar 解包 ``` jar -xvf xxx.jar ``` --- 資料來源: [Installing Apache Maven](https://maven.apache.org/install.html) - apache.org [解决:target\surefire-reports for the individual test results](https://www.cnblogs.com/ios9/p/14811278.html)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up