User Tools

Site Tools


java:build-java

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java:build-java [2017/09/06 09:53] – [maven] adminjava:build-java [2024/04/19 03:24] (current) – [Prepare environment variables] admin
Line 4: Line 4:
 d:\tools\jdk1.7.0_67\bin;D:\tools\apache-ant-1.8.4\bin;D:\tools\apache-maven-3.2.3\bin; d:\tools\jdk1.7.0_67\bin;D:\tools\apache-ant-1.8.4\bin;D:\tools\apache-maven-3.2.3\bin;
 </code> </code>
-  * add new environment variable JAVA_HOME<code>+  * add new environment variable JAVA_HOME(Change **Environment Variables in Windows**)<code>
 d:\tools\jdk1.7.0_67 d:\tools\jdk1.7.0_67
 </code> </code>
Line 34: Line 34:
 java -jar build\jar\helloworld.jar java -jar build\jar\helloworld.jar
 </code> </code>
 +
 ==== compile and run with external libraries(log4j) ==== ==== compile and run with external libraries(log4j) ====
   * update code to use log4j2<code java>   * update code to use log4j2<code java>
Line 266: Line 267:
 cd simplemaven cd simplemaven
 mvn compile mvn compile
-</code>+</code> => maven will download all **dependency packages** to **~/.m2**
   - Step4: Run<code bat>   - Step4: Run<code bat>
 java -cp target\simplemaven-1.0-SNAPSHOT.jar com.mycompany.App java -cp target\simplemaven-1.0-SNAPSHOT.jar com.mycompany.App
Line 305: Line 306:
 mvn compile mvn compile
 </code> </code>
 +  * maven **search** packages: http://search.maven.org/ or https://mvnrepository.com/
 ==== Set main class for packaging jar file ==== ==== Set main class for packaging jar file ====
   - Step1: Add build config for pom.xml which set** main class** is **com.mycompany.Helloworld**:<code xml>   - Step1: Add build config for pom.xml which set** main class** is **com.mycompany.Helloworld**:<code xml>
Line 544: Line 546:
 gradle gradle
 </code> </code>
-  - Step3: Click Install **Buildship Gradle Integration 2.0** or Install +  - Step3: Click Install **Buildship Gradle Integration 2.0** or Install **Gradle IDE Pack** 
 +==== Add Depedency Package ==== 
 +refer: https://docs.gradle.org/3.3/userguide/dependency_management.html 
 +  - Step1: Goto pages below to search maven packages:  
 +    * http://search.maven.org/ 
 +    * or https://mvnrepository.com/ 
 +  - Step2: search depedency package, for example "libgdx", we will see info of package below:<code xml> 
 +<dependency> 
 +    <groupId>com.badlogicgames.gdx</groupId> 
 +    <artifactId>gdx</artifactId> 
 +    <version>1.9.6</version> 
 +</dependency> 
 +</code> 
 +  - Step3: Configure depedency in **build.gradle**<code json> 
 +project(":core") { 
 +    apply plugin: "java" 
 + 
 + 
 +    dependencies { 
 +        compile "com.badlogicgames.gdx:gdx:1.9.6" 
 +............................... 
 +    } 
 +
 +</code> 
 + 
 +==== Clear Gradle caches ==== 
 +Go to **C:\Users\anhvc\.gradle** and **delete all files** and directories in this directory 
 +=> Fix error run gradle when you **change java version from 1.8 to 1.7**. When you change java version, you must reload new jar packages of gradle in new version 1.7 
 +==== Fix error build with gradle when change default java form 1.8 to 1.7 ==== 
 +I 've tried installing Java 8, and setting my project to use Java 8. If I change my JAVA_HOME to 1.8 on the command line and compile with gradle it works. If I try to use JAVA_HOME set to 1.7 and gradle it fails with the same error. 
 +<code> 
 +java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0 
 +</code> 
 +=> Fix: set JAVA_HOME and PATH to java8
 ===== Build Java with eclipse ===== ===== Build Java with eclipse =====
 ==== Add jars or class build path ==== ==== Add jars or class build path ====
Line 550: Line 585:
 ==== Add required project ==== ==== Add required project ====
 {{:java:eclipse-project-depedency.png|}} {{:java:eclipse-project-depedency.png|}}
 +===== Proguard =====
 +refer: https://www.guardsquare.com/en/proguard
java/build-java.1504691639.txt.gz · Last modified: 2022/10/29 16:15 (external edit)