joplin-notes/joplin notion extension/Web Development/Java/Extras.md
2026-11-04 00:33:23 +05:30

56 lines
No EOL
2 KiB
Markdown

Extras
- Alternaive of String.format in java
```java
String sql = "SELECT ${columns} FROM Users WHERE Lastname=?"
.replace("${columns}", "name");
```
- Maven
Maven Build Lifecycle Phases
Maven follows a build lifecycle consisting of several phases. When you run mvn package, Maven executes all preceding phases in the lifecycle:
```text
validate: Checks if the project is correct and all necessary information is available.
compile: Compiles the source code.
test-compile: Compiles the test source code.
test: Runs the tests using the compiled test code.
package: Packages the compiled code and resources into a JAR, WAR, or other artifact formats.
```
If you run `mvn test`, Maven will perform only up to the test phase. It does not proceed to the package phase, so no artifact will be created.
When creating any maven project directory structure should be like this
```text
my-project/
├── pom.xml
├── src/
├── main/
├── java/
└── com/
└── example/
└── MyClass.java
├── resources/
└── config.properties
├── test/
├── java/
└── com/
└── example/
└── MyClassTest.java
├── resources/
└── test-config.properties
```
- Creating a jar file
- First compile the java code to some directory say `bin`
`javac -d bin main.java` (-d bin to create a directory)
- `jar cf proj.jar -C bin .` (c for creative archve , f to specify name of jar file, -C bin . to change to bin directory from current one)
- for creating executable jar manifest file needs to be created too so create a file with name `MANIFEST.MF` an type following
```makefile
Manifest-Version: 1.0
Main-Class: HelloWorld
```
Then add it in jar with
`jar cfm proj.jar MANIFEST.MF -C bin .`
- `jar tf proj.jar` : to verify it
- `java -jar proj.jar`
 
handling JSON in java
- https://www.geeksforgeeks.org/parse-json-java/