-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava
More file actions
executable file
·175 lines (135 loc) · 3.89 KB
/
java
File metadata and controls
executable file
·175 lines (135 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
# Define project structure
PROJECT_NAME="javastarter"
SRC_DIR="$PROJECT_NAME/src/main/java/com/example"
TEST_DIR="$PROJECT_NAME/src/test/java/com/example"
BIN_DIR="$PROJECT_NAME/bin"
DOCS_DIR="$PROJECT_NAME/docs"
# Create necessary directories
mkdir -p "$SRC_DIR" "$TEST_DIR" "$BIN_DIR" "$DOCS_DIR"
# Create a sample Java main file
cat <<EOL > "$SRC_DIR/Main.java"
package com.example;
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java Starter Project!");
}
}
EOL
# Create a sample Java helper class
cat <<EOL > "$SRC_DIR/utils/Helper.java"
package com.example.utils;
public class Helper {
public static String getMessage() {
return "This is a helper method!";
}
}
EOL
# Create a sample Java test file
cat <<EOL > "$TEST_DIR/MainTest.java"
package com.example;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class MainTest {
@Test
public void testExample() {
assertEquals(1, 1);
}
}
EOL
# Create an installation script
cat <<EOL > "$PROJECT_NAME/install.sh"
#!/bin/bash
# Create bin directory if not exists
mkdir -p bin
# Compile Java files
javac -d bin src/main/java/com/example/*.java src/main/java/com/example/utils/*.java
echo "Project compiled successfully!"
# Run the Java program
echo "Running the program..."
java -cp bin com.example.Main
EOL
chmod +x "$PROJECT_NAME/install.sh"
# Create a Makefile
cat <<EOL > "$PROJECT_NAME/Makefile"
CC = javac
JAVA = java
SRC = src/main/java
BIN = bin
all:
\tmkdir -p \$(BIN)
\t\$(CC) -d \$(BIN) \$(SRC)/com/example/*.java \$(SRC)/com/example/utils/*.java
run:
\t\$(JAVA) -cp \$(BIN) com.example.Main
docs:
\tjavadoc -d docs -sourcepath src/main/java -subpackages com.example
clean:
\trm -rf \$(BIN)/* docs/*
EOL
# Create a README file
cat <<EOL > "$PROJECT_NAME/README.md"
# **Java Starter Project**
This is a simple Java starter project. You can clone this repository and start working on Java code immediately.
---
## **Installation**
### **1. Clone the repository**
\`\`\`bash
git clone https://github.com/csode/javastarter.git
\`\`\`
### **2. Navigate into the project directory**
\`\`\`bash
cd javastarter
\`\`\`
### **3. Build and set up the project**
Run the installation script:
\`\`\`bash
./install.sh
\`\`\`
This script will compile your Java files and set up the necessary directory structure.
---
## **Project Structure**
The project follows a structured template for easy organization:
\`\`\`
javastarter/
│── src/
│ ├── main/java/com/example/Main.java
│ ├── main/java/com/example/utils/Helper.java
│ ├── test/java/com/example/MainTest.java
│── bin/ # Compiled Java bytecode
│── docs/ # Javadoc documentation
│── install.sh # Installation script
│── Makefile # Optional: Automate build & run commands
│── README.md # Project documentation
\`\`\`
### **Directories Explained**
- \`src/main/java/\` → Main source code
- \`src/test/java/\` → Unit tests
- \`bin/\` → Compiled class files
- \`docs/\` → Generated Javadoc documentation
- \`install.sh\` → Script to compile and run the project
- \`Makefile\` → Automate build/test/docs generation
---
## **Usage**
### **Run the Java program**
\`\`\`bash
java -cp bin com.example.Main
\`\`\`
### **Run Tests (if applicable)**
\`\`\`bash
java -cp bin org.junit.runner.JUnitCore com.example.MainTest
\`\`\`
### **Generate Javadoc**
\`\`\`bash
javadoc -d docs -sourcepath src/main/java -subpackages com.example
\`\`\`
To view the documentation locally, open:
\`\`\`bash
xdg-open docs/index.html # Linux
open docs/index.html # macOS
start docs/index.html # Windows
\`\`\`
---
## **Contributing**
If you’d like to contribute, feel free to fork the repository and submit a pull request.
EOL
echo "Java starter project '$PROJECT_NAME' created successfully!"