MCPcopy Create free account
hub / github.com/astonbitecode/j4rs / build

Method build

rust/src/api/mod.rs:1883–2031  ·  view source on GitHub ↗

Creates a Jvm

(&mut self)

Source from the content-addressed store, hash-verified

1881
1882 /// Creates a Jvm
1883 pub fn build(&mut self) -> errors::Result<Jvm> {
1884 if !self.default_classloader {
1885 // Define the system classloader
1886 self.java_opts.push(JavaOpt::new(
1887 "-Djava.system.class.loader=org.astonbitecode.j4rs.api.deploy.J4rsClassLoader",
1888 ));
1889 self.java_opts.push(JavaOpt::new("-Xshare:off"));
1890 self.java_opts.push(JavaOpt::new(
1891 "-Djdk.net.URLClassPath.showIgnoredClassPathEntries=true",
1892 ));
1893 }
1894
1895 let classpath = if self.no_implicit_classpath {
1896 self.classpath_entries
1897 .iter()
1898 .fold(".".to_string(), |all, elem| {
1899 format!("{}{}{}", all, utils::classpath_sep(), elem.to_string())
1900 })
1901 } else {
1902 // The default classpath contains all the jars in the jassets directory
1903 let jassets_path = self.get_jassets_path()?;
1904 // This is the j4rs jar that should be included in the classpath
1905 let j4rs_jar_to_use = format!("j4rs-{}-jar-with-dependencies.jar", j4rs_version());
1906 let j4rs_testing_jar_to_use = format!("j4rs-testing-{}.jar", j4rs_version());
1907 let j4rs_javafx_jar_to_use = format!("j4rs-javafx-{}.jar", j4rs_version());
1908 // Filter out possible incorrect jars of j4rs
1909 let mut cp_string = String::new();
1910 for entry in std::fs::read_dir(jassets_path)? {
1911 let path = entry?.path();
1912 if let Some(file_name) = opt_to_res(path.file_name())?.to_str() {
1913 if !file_name.contains("j4rs-")
1914 || file_name.ends_with(&j4rs_jar_to_use)
1915 || file_name.ends_with(&j4rs_testing_jar_to_use)
1916 || file_name.ends_with(&j4rs_javafx_jar_to_use)
1917 {
1918 if !cp_string.is_empty() {
1919 cp_string.push_str(utils::classpath_sep());
1920 }
1921 if let Some(path) = path.to_str() {
1922 cp_string.push_str(path);
1923 }
1924 }
1925 }
1926 }
1927
1928 let default_class_path = format!("-Djava.class.path={}", cp_string);
1929
1930 self.classpath_entries
1931 .iter()
1932 .fold(default_class_path, |all, elem| {
1933 format!("{}{}{}", all, utils::classpath_sep(), elem.to_string())
1934 })
1935 };
1936 info(&format!("Setting classpath to {}", classpath));
1937
1938 // Populate the JVM Options
1939 let mut jvm_options = if self.no_implicit_classpath {
1940 vec![classpath]

Callers 6

j4rs_benchmarkFunction · 0.80
new_jvmFunction · 0.80
create_tests_jvmFunction · 0.80
parsePomMethod · 0.80

Calls 13

opt_to_resFunction · 0.85
classpath_sepFunction · 0.85
infoFunction · 0.85
java_library_pathFunction · 0.85
deps_dirFunction · 0.85
set_maven_settingsFunction · 0.85
to_stringMethod · 0.80
get_jassets_pathMethod · 0.80
collectMethod · 0.80
detach_thread_on_dropMethod · 0.80
set_java_vmFunction · 0.50