FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-code-example/ClassLoader/JarLoader.java at master · cherkavi/java-code-example · GitHub
cherkavi
/
java-code-example
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
0
Code
Issues
0
Pull requests
42
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-code-example
/
ClassLoader
/
JarLoader.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
47 lines (38 loc) · 1.49 KB
Breadcrumbs
java-code-example
/
ClassLoader
/
JarLoader.java
Copy path
File metadata and controls
executable file
·
47 lines (38 loc) · 1.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
io
.*;
import
java
.
net
.*;
import
java
.
util
.
jar
.*;
public
class
JarLoader
{
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
,
IOException
{
String
jarName
=
"c:/temp/temp.jar"
;
// çàìåíèòü íà ñâîé
URLClassLoader
urlLoader
=
getURLClassLoader
(
new
URL
(
"file"
,
null
,
jarName
));
JarInputStream
jis
=
new
JarInputStream
(
new
FileInputStream
(
jarName
));
JarEntry
entry
=
jis
.
getNextJarEntry
();
int
loadedCount
=
0
,
totalCount
=
0
;
while
(
entry
!=
null
) {
String
name
=
entry
.
getName
();
if
(
name
.
endsWith
(
".class"
)) {
totalCount
++;
name
=
name
.
substring
(
0
,
name
.
length
() -
6
);
name
=
name
.
replace
(
'/'
,
'.'
);
System
.
out
.
print
(
"> "
+
name
);
try
{
urlLoader
.
loadClass
(
name
);
System
.
out
.
println
(
"
\t
- loaded"
);
loadedCount
++;
}
catch
(
Throwable
e
) {
System
.
out
.
println
(
"
\t
- not loaded"
);
System
.
out
.
println
(
"
\t
"
+
e
.
getClass
().
getName
() +
": "
+
e
.
getMessage
());
}
}
entry
=
jis
.
getNextJarEntry
();
}
System
.
out
.
println
(
"
\n
---------------------"
);
System
.
out
.
println
(
"Summary:"
);
System
.
out
.
println
(
"
\t
Loaded:
\t
"
+
loadedCount
);
System
.
out
.
println
(
"
\t
Failed:
\t
"
+ (
totalCount
-
loadedCount
));
System
.
out
.
println
(
"
\t
Total:
\t
"
+
totalCount
);
}
private
static
URLClassLoader
getURLClassLoader
(
URL
jarURL
) {
return
new
URLClassLoader
(
new
URL
[]{
jarURL
});
}
}
Back
|
FazBrowse Home
|
New Git URL