Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to refer and import SAP-UI-Core.js within my SAPUI5 project
The SAPUI5 library files are a part of Eclipse SAPUI5 plug-in. The sap-ui-core.js file is the core JavaScript file that bootstraps the SAPUI5 framework and must be properly referenced in your project.
If you are running the app by using the Web App preview on the startup page (Go to Run As ? select "Web APP Preview"), then Eclipse starts a local HTTP server for development which serves the library at "/resources".
Till the preview window is open, you can go ahead and use the URL in any browser of your choice to debug the application.
Methods to Reference sap-ui-core.js
Method 1: Local Reference
When using Eclipse with SAPUI5 plugin, reference the core library locally ?
<script src="/resources/sap-ui-core.js"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-libs="sap.m">
</script>
Method 2: CDN Reference
For production or when not using Eclipse, reference from SAP's CDN ?
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-libs="sap.m"
data-sap-ui-resourceroots='{
"com.company.myapp": "./"
}'>
</script>
Complete HTML Example
Here's a complete HTML file showing proper sap-ui-core.js integration ?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SAPUI5 App</title>
<script src="/resources/sap-ui-core.js"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-libs="sap.m">
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
<script>
sap.ui.getCore().attachInit(function() {
// Your app initialization code here
});
</script>
</body>
</html>
Important Attributes
Key attributes for the script tag ?
-
data-sap-ui-theme? Defines the visual theme -
data-sap-ui-libs? Specifies required UI libraries -
data-sap-ui-resourceroots? Maps namespace to file paths
Conclusion
Referencing sap-ui-core.js correctly is essential for SAPUI5 applications. Use local paths during development with Eclipse and CDN URLs for production deployment.
