SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Java ClassLoader
java.lang.ClassNotFoundException
Xuefeng.Wu
明明就在这里啊!
ClassNotFoundException
When
 Class.forName()
 findSystemClass()
 loadClass()
 NoClassDefFoundError: compile time
Run time
Agenda
 JVM class and execute
 Core ClassLoader and MyClassLoader
 Tools: jps, jinfo
 Eclipse-OSGi
 Maven
 Spring
 Dynamic Classes and Method (Reflect, Java 8)
 Other: MethodNotDef
Agenda
 JVM class and execute
 Core ClassLoader and MyClassLoader
 Tools: jps, jinfo
 Eclipse-OSGi
 Maven
 Spring
 Dynamic Classes and Method (Reflect, Java 8)
 Other: MethodNotDef
Key JVM Components
Agenda
 JVM class and execute
 Core ClassLoader and MyClassLoader
 Tools: jps, jinfo
 Eclipse-OSGi
 Maven
 Spring
 Dynamic Classes and Method (Reflect, Java 8)
 Other: MethodNotDef
Default class loader
sun.misc.Launcher$ExtClassLoader
sun.misc.Launcher$AppClassLoader
CLASSPATH environment variable,
-classpath or -cp command line option,
Class-Path attribute of Manifest file inside JAR
Tools: jps, jinfo
ClassLoader works
MyClassLoader
DEMO:MyClassLoader
Three principles
 Delegation principles
 Visibility Principle
 Uniqueness Principle
Child ClassLoader can see class loaded by Parent ClassLoad
but vice-versa is not true.
According to this principle a class loaded by Parent
should not be loaded by Child ClassLoader again.
DEMO:demo. ExplicitlyLoadClassByExtension
Is it easy?
Agenda
 JVM class and execute
 Core ClassLoader and MyClassLoader
 Tools: jps, jinfo
 Eclipse-OSGi
 Maven
 Spring
 Dynamic Classes and Method (Reflect, Java 8)
 Other: MethodNotDef
Eclipse-OSGi
OSGi Class Loader
Demo
 Run Plugin_ListAll_Normal
 Jinfo
Demo
 Debug Plugin_ListAll_Normal
Demo
 Debug HelloWorld in remote project
Issue & fix
 Try to find csdm/client/StartUp.class is exist.
Agenda
 JVM class and execute
 Core ClassLoader and MyClassLoader
 Tools: jps, jinfo
 Eclipse-OSGi
 Maven
 Spring
 Dynamic Classes and Method (Reflect, Java 8)
 Other: MethodNotDef
Maven
 System Classloader: Classworlds classloading
framework

 Core Classloader:
 Plugin Classloaders
 Custom Classloaders
boot the classloader graph: ${maven.home}/boot
down the graph contains the core requirements of
Maven:
${maven.home}/lib
each plugin has its own classloader
that is a child of Maven's core classloader
plugins/plugin
Demo: jetty plugin
 mvn jetty:run @ remote
a limit on how long you can make your
command line
 Isolaed Classloader: your classpath
isn't really correct. try to escape the confines of an
isolated classloader.
 Manifest-Only JAR:your app may be confused if it
finds only our booter.jar there!
Demo: surefire plugin
 mvn -Dtest=* test
Agenda
 JVM class and execute
 Core ClassLoader and MyClassLoader
 Tools: jps, jinfo
 Eclipse-OSGi
 Maven
 Spring
 Dynamic Classes and Method (Reflect, Java 8)
 Other: MethodNotDef
Spring
String bean = readerBeanClass()
Class clz = classLoader.loadClass(bean)
clz .newInstance()
Spring ResourceLoader
 ClassPathXmlApplicationContext
 DefaultResourceLoader.
 setClassLoader(ClassLoader classLoader)
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader();
reader.setBeanClassLoader([Class LoaderB here!]);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(reader);
reader.loadBeanDefinitions([xml resource here!]);
Default: thread context class loader: Thread.currentThread().getContextClassLoader()
Issue & fix
Agenda
 JVM class and execute
 Core ClassLoader and MyClassLoader
 Tools: jps, jinfo
 Eclipse-OSGi
 Maven
 Spring
 Dynamic Classes and Method (Reflect, Java 8)
 Other: MethodNotDef
Agenda
 JVM class and execute
 Core ClassLoader and MyClassLoader
 Tools: jps, jinfo
 Eclipse-OSGi
 Maven
 Spring
 Dynamic Classes and Method (Reflect, Java 8)
 Other: MethodNotDef
Other: MethodNotDef
 Jar version
Class.forName(“...HelloWorld")
public class com.carestreamhealth.pas.RemoteWS.utils.HelloWorld {
public com.carestreamhealth.pas.RemoteWS.utils.HelloWorld();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.lang.ClassNotFoundException;
Code:
0: ldc #19 // String
com.carestreamhealth.pas.RemoteWS.utils.HelloWorld
2: invokestatic #21 // Method
java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
5: pop
6: return
}
getClassLoader().loadClass(“..HelloWorld")
public class com.carestreamhealth.pas.RemoteWS.utils.HelloWorld {
public com.carestreamhealth.pas.RemoteWS.utils.HelloWorld();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.lang.ClassNotFoundExce
ption, java.lang.InstantiationException, java.lang.IllegalAccessException;
Code:
0: ldc #1 // class
com/carestreamhealth/pas/RemoteWS/utils/HelloWorld
2: invokevirtual #23 // Method
java/lang/Class.getClassLoader:()Ljava/lang/ClassLoader;
5: ldc #29 // String
com.carestreamhealth.pas.RemoteWS.utils.HelloWorld
7: invokevirtual #31 // Method
java/lang/ClassLoader.loadClass:(Ljava/lang/String;)Ljava/lang/Class;
10: pop
11: return
}
new HelloWorld
public class com.carestreamhealth.pas.RemoteWS.utils.HelloWorld {
public com.carestreamhealth.pas.RemoteWS.utils.HelloWorld();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":
()V
4: return
public static void main(java.lang.String[]);
Code:
0: new #1 // class com/carestreamhealth/pas/Re
moteWS/utils/HelloWorld
3: invokespecial #16 // Method "<init>":()V
6: return
}
Call Site-VM Operation
JVM Spec: 5.3 Creation and Loading
http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html
Dynamic Classes and Method (Reflect, Java
8)
 invokedynamic
http://www.slideshare.net/CharlesNutter/jax-2012-invoke-dynamic-keynote
Java bytecode:
Understanding bytecode makes you a
better programmer
Example:
http://www.ibm.com/developerworks/ibm/library/it-haggar_bytecode/
Java Class:
http://en.wikipedia.org/wiki/Java_class_file
Java bytecodes:
http://en.wikipedia.org/wiki/Java_bytecode_instruction_listings
Java class loader

Weitere ähnliche Inhalte

Was ist angesagt?

Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers GuideDaisyWatson5
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesRafael Luque Leiva
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx FranceDavid Delabassee
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satyaSatya Johnny
 
Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming languagemasud33bd
 
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsCS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsKwangshin Oh
 
Smalltalk on the JVM
Smalltalk on the JVMSmalltalk on the JVM
Smalltalk on the JVMESUG
 
Class method object
Class method objectClass method object
Class method objectMinal Maniar
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz SAurabh PRajapati
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machineLaxman Puri
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924yohanbeschi
 
Manuel - SPR - Intro to Java Language_2016
Manuel - SPR - Intro to Java Language_2016Manuel - SPR - Intro to Java Language_2016
Manuel - SPR - Intro to Java Language_2016Manuel Fomitescu
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT studentsPartnered Health
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basicstosine
 

Was ist angesagt? (20)

Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic Proxies
 
Dynamic Proxy by Java
Dynamic Proxy by JavaDynamic Proxy by Java
Dynamic Proxy by Java
 
Class loaders
Class loadersClass loaders
Class loaders
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France
 
Basics of java
Basics of javaBasics of java
Basics of java
 
testing ppt
testing ppttesting ppt
testing ppt
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
 
Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming language
 
Java Tutorial 1
Java Tutorial 1Java Tutorial 1
Java Tutorial 1
 
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsCS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
 
Smalltalk on the JVM
Smalltalk on the JVMSmalltalk on the JVM
Smalltalk on the JVM
 
Class method object
Class method objectClass method object
Class method object
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924
 
INTRODUCTION TO JAVA
INTRODUCTION TO JAVAINTRODUCTION TO JAVA
INTRODUCTION TO JAVA
 
Manuel - SPR - Intro to Java Language_2016
Manuel - SPR - Intro to Java Language_2016Manuel - SPR - Intro to Java Language_2016
Manuel - SPR - Intro to Java Language_2016
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
 

Ähnlich wie Java class loader

Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpathAlexis Hassler
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
LorraineJUG - Le classpath n'est pas mort
LorraineJUG - Le classpath n'est pas mortLorraineJUG - Le classpath n'est pas mort
LorraineJUG - Le classpath n'est pas mortAlexis Hassler
 
How to run java program without IDE
How to run java program without IDEHow to run java program without IDE
How to run java program without IDEShweta Oza
 
ElsassJUG - Le classpath n'est pas mort...
ElsassJUG - Le classpath n'est pas mort...ElsassJUG - Le classpath n'est pas mort...
ElsassJUG - Le classpath n'est pas mort...Alexis Hassler
 
Java questions with answers
Java questions with answersJava questions with answers
Java questions with answersKuntal Bhowmick
 
RelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaRelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaJose María Arranz
 
Perils Of Url Class Loader
Perils Of Url Class LoaderPerils Of Url Class Loader
Perils Of Url Class LoaderKaniska Mandal
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMmanish kumar
 
Jpf model checking
Jpf model checkingJpf model checking
Jpf model checkingthought444
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAVINASH KUMAR
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeOmar Bashir
 

Ähnlich wie Java class loader (20)

Diving into Java Class Loader
Diving into Java Class LoaderDiving into Java Class Loader
Diving into Java Class Loader
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
 
Class
ClassClass
Class
 
Class
ClassClass
Class
 
Class
ClassClass
Class
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
LorraineJUG - Le classpath n'est pas mort
LorraineJUG - Le classpath n'est pas mortLorraineJUG - Le classpath n'est pas mort
LorraineJUG - Le classpath n'est pas mort
 
How to run java program without IDE
How to run java program without IDEHow to run java program without IDE
How to run java program without IDE
 
Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
 
ElsassJUG - Le classpath n'est pas mort...
ElsassJUG - Le classpath n'est pas mort...ElsassJUG - Le classpath n'est pas mort...
ElsassJUG - Le classpath n'est pas mort...
 
Java basics
Java basicsJava basics
Java basics
 
Java questions with answers
Java questions with answersJava questions with answers
Java questions with answers
 
RelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaRelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with Java
 
Perils Of Url Class Loader
Perils Of Url Class LoaderPerils Of Url Class Loader
Perils Of Url Class Loader
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
 
Jpf model checking
Jpf model checkingJpf model checking
Jpf model checking
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and Runtime
 
Java Intro
Java IntroJava Intro
Java Intro
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 

Kürzlich hochgeladen

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Kürzlich hochgeladen (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Java class loader

  • 4. When  Class.forName()  findSystemClass()  loadClass()  NoClassDefFoundError: compile time Run time
  • 5. Agenda  JVM class and execute  Core ClassLoader and MyClassLoader  Tools: jps, jinfo  Eclipse-OSGi  Maven  Spring  Dynamic Classes and Method (Reflect, Java 8)  Other: MethodNotDef
  • 6. Agenda  JVM class and execute  Core ClassLoader and MyClassLoader  Tools: jps, jinfo  Eclipse-OSGi  Maven  Spring  Dynamic Classes and Method (Reflect, Java 8)  Other: MethodNotDef
  • 8. Agenda  JVM class and execute  Core ClassLoader and MyClassLoader  Tools: jps, jinfo  Eclipse-OSGi  Maven  Spring  Dynamic Classes and Method (Reflect, Java 8)  Other: MethodNotDef
  • 9. Default class loader sun.misc.Launcher$ExtClassLoader sun.misc.Launcher$AppClassLoader CLASSPATH environment variable, -classpath or -cp command line option, Class-Path attribute of Manifest file inside JAR
  • 13. Three principles  Delegation principles  Visibility Principle  Uniqueness Principle Child ClassLoader can see class loaded by Parent ClassLoad but vice-versa is not true. According to this principle a class loaded by Parent should not be loaded by Child ClassLoader again. DEMO:demo. ExplicitlyLoadClassByExtension
  • 15. Agenda  JVM class and execute  Core ClassLoader and MyClassLoader  Tools: jps, jinfo  Eclipse-OSGi  Maven  Spring  Dynamic Classes and Method (Reflect, Java 8)  Other: MethodNotDef
  • 20. Demo  Debug HelloWorld in remote project
  • 21. Issue & fix  Try to find csdm/client/StartUp.class is exist.
  • 22. Agenda  JVM class and execute  Core ClassLoader and MyClassLoader  Tools: jps, jinfo  Eclipse-OSGi  Maven  Spring  Dynamic Classes and Method (Reflect, Java 8)  Other: MethodNotDef
  • 23. Maven  System Classloader: Classworlds classloading framework   Core Classloader:  Plugin Classloaders  Custom Classloaders boot the classloader graph: ${maven.home}/boot down the graph contains the core requirements of Maven: ${maven.home}/lib each plugin has its own classloader that is a child of Maven's core classloader plugins/plugin
  • 24. Demo: jetty plugin  mvn jetty:run @ remote
  • 25. a limit on how long you can make your command line  Isolaed Classloader: your classpath isn't really correct. try to escape the confines of an isolated classloader.  Manifest-Only JAR:your app may be confused if it finds only our booter.jar there!
  • 26. Demo: surefire plugin  mvn -Dtest=* test
  • 27. Agenda  JVM class and execute  Core ClassLoader and MyClassLoader  Tools: jps, jinfo  Eclipse-OSGi  Maven  Spring  Dynamic Classes and Method (Reflect, Java 8)  Other: MethodNotDef
  • 28. Spring String bean = readerBeanClass() Class clz = classLoader.loadClass(bean) clz .newInstance()
  • 29. Spring ResourceLoader  ClassPathXmlApplicationContext  DefaultResourceLoader.  setClassLoader(ClassLoader classLoader) XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(); reader.setBeanClassLoader([Class LoaderB here!]); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(reader); reader.loadBeanDefinitions([xml resource here!]); Default: thread context class loader: Thread.currentThread().getContextClassLoader()
  • 31. Agenda  JVM class and execute  Core ClassLoader and MyClassLoader  Tools: jps, jinfo  Eclipse-OSGi  Maven  Spring  Dynamic Classes and Method (Reflect, Java 8)  Other: MethodNotDef
  • 32. Agenda  JVM class and execute  Core ClassLoader and MyClassLoader  Tools: jps, jinfo  Eclipse-OSGi  Maven  Spring  Dynamic Classes and Method (Reflect, Java 8)  Other: MethodNotDef
  • 34. Class.forName(“...HelloWorld") public class com.carestreamhealth.pas.RemoteWS.utils.HelloWorld { public com.carestreamhealth.pas.RemoteWS.utils.HelloWorld(); Code: 0: aload_0 1: invokespecial #8 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]) throws java.lang.ClassNotFoundException; Code: 0: ldc #19 // String com.carestreamhealth.pas.RemoteWS.utils.HelloWorld 2: invokestatic #21 // Method java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class; 5: pop 6: return }
  • 35. getClassLoader().loadClass(“..HelloWorld") public class com.carestreamhealth.pas.RemoteWS.utils.HelloWorld { public com.carestreamhealth.pas.RemoteWS.utils.HelloWorld(); Code: 0: aload_0 1: invokespecial #8 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]) throws java.lang.ClassNotFoundExce ption, java.lang.InstantiationException, java.lang.IllegalAccessException; Code: 0: ldc #1 // class com/carestreamhealth/pas/RemoteWS/utils/HelloWorld 2: invokevirtual #23 // Method java/lang/Class.getClassLoader:()Ljava/lang/ClassLoader; 5: ldc #29 // String com.carestreamhealth.pas.RemoteWS.utils.HelloWorld 7: invokevirtual #31 // Method java/lang/ClassLoader.loadClass:(Ljava/lang/String;)Ljava/lang/Class; 10: pop 11: return }
  • 36. new HelloWorld public class com.carestreamhealth.pas.RemoteWS.utils.HelloWorld { public com.carestreamhealth.pas.RemoteWS.utils.HelloWorld(); Code: 0: aload_0 1: invokespecial #8 // Method java/lang/Object."<init>": ()V 4: return public static void main(java.lang.String[]); Code: 0: new #1 // class com/carestreamhealth/pas/Re moteWS/utils/HelloWorld 3: invokespecial #16 // Method "<init>":()V 6: return }
  • 38. JVM Spec: 5.3 Creation and Loading http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html
  • 39. Dynamic Classes and Method (Reflect, Java 8)  invokedynamic http://www.slideshare.net/CharlesNutter/jax-2012-invoke-dynamic-keynote
  • 40. Java bytecode: Understanding bytecode makes you a better programmer Example: http://www.ibm.com/developerworks/ibm/library/it-haggar_bytecode/ Java Class: http://en.wikipedia.org/wiki/Java_class_file Java bytecodes: http://en.wikipedia.org/wiki/Java_bytecode_instruction_listings

Hinweis der Redaktion

  1. package demo;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;/** * Created with IntelliJ IDEA. * User: 19002850 * Date: 13-5-20 * Time: 下午4:35 * To change this template use File | Settings | File Templates. */public class MyClassLoader extends ClassLoader { private static final int BUFFER_SIZE = 8192; protected synchronized Class loadClass(String className, boolean resolve) throws ClassNotFoundException { log(&quot;Loading class: &quot; + className + &quot;, resolve: &quot; + resolve); // 1. is this class already loaded? Class cls = findLoadedClass(className); if (cls != null) { return cls; } // 2. get class file name from class name String clsFile = className.replace(&apos;.&apos;, &apos;/&apos;) + &quot;.class&quot;; // 3. get bytes for class byte[] classBytes = null; try {InputStream in = getResourceAsStream(clsFile); byte[] buffer = new byte[BUFFER_SIZE];ByteArrayOutputStream out = new ByteArrayOutputStream();int n = -1; while ((n = in.read(buffer, 0, BUFFER_SIZE)) != -1) {out.write(buffer, 0, n); }classBytes = out.toByteArray(); } catch (IOException e) { log(&quot;ERROR loading class file: &quot; + e); } if (classBytes == null) { throw new ClassNotFoundException(&quot;Cannot load class: &quot; + className); } // 4. turn the byte array into a Class try {cls = defineClass(className, classBytes, 0, classBytes.length); if (resolve) {resolveClass(cls); } } catch (SecurityException e) { // loading core java classes such as java.lang.String // is prohibited, throws java.lang.SecurityException. // delegate to parent if not allowed to load classcls = super.loadClass(className, resolve); } return cls; } private static void log(String s) {System.out.println(s); }}
  2. package demo;import java.util.logging.Level;import java.util.logging.Logger;/** * Java program to demonstrate How ClassLoader works in Java, * in particular about visibility principle of ClassLoader. * * @author Javin Paul */public class ExplicitlyLoadClassByExtension { public static void main(String args[]) { try { //printing ClassLoader of this classSystem.out.println(&quot;-------------&quot;);System.out.println(&quot;ExplicitlyLoadClassByExtension.getClass().getClassLoader() : &quot; + ExplicitlyLoadClassByExtension.class.getClassLoader()); //trying to explicitly load this class again using Extension class loaderSystem.out.println(&quot;ExplicitlyLoadClassByExtension.getClass().getClassLoader().getParent() : &quot; + ExplicitlyLoadClassByExtension.class.getClassLoader().getParent());Class.forName(&quot;demo.ExplicitlyLoadClassByExtension&quot;, true , ExplicitlyLoadClassByExtension.class.getClassLoader().getParent()); } catch (ClassNotFoundException ex) {Logger.getLogger(ExplicitlyLoadClassByExtension.class.getName()).log(Level.SEVERE, null, ex); } }}