-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclassloading.cpp
More file actions
51 lines (45 loc) · 1.11 KB
/
classloading.cpp
File metadata and controls
51 lines (45 loc) · 1.11 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
/*
* classloading.cpp
*
* Created on: 25 nov. 2013
* Author: Loic Oudot
*/
#include <iostream>
#include "java4cpp/java_classes.h"
#include "java4cpp/jvm_launcher.h"
#include "classloading.h"
using namespace java4cpp::demos;
void allClassloading()
{
std::cout << "================================" << std::endl;
std::cout << "Class Loading" << std::endl;
std::cout << "================================" << std::endl;
dynamicClassloader();
}
void dynamicClassloader()
{
// try to instanciate unknow class
std::cout << "not in class path: ";
try
{
org::slf4j::helpers::BasicMarkerFactory factory;
std::cout << "ko";
} catch (std::exception& )
{
std::cout << "ok";
}
std::cout << std::endl;
// add a jar dynaically in class path
jvm_addClassPath("../../jars/slf4j-api-1.7.5.jar");
// retry to instanciate
std::cout << "now in class path: ";
try
{
org::slf4j::helpers::BasicMarkerFactory factory;
std::cout << "ok";
} catch (std::exception& e)
{
std::cout << "ko" << std::endl << e.what();
}
std::cout << std::endl;
}