我对 java 解释器和 java 编译器如何从环境变量中搜索它所需的所有必要的 jar 文件感到困惑。因为我只设置了 JDK 目录的 set path 变量,但没有设置任何变量来搜索 jvm 需要的任何类库。它如何搜索那些重要的jar文件?
将依赖项 jar 添加到 RAD 项目中的 .classpath 文件与将依赖项添加到 MANIFEST.MF 文件之间有什么区别?
我有一个项目使用两个版本的 bouncyCastle jars bcprov-jdk15 和 bcprov-jdk16。jvm 加载旧版本,但我编写的一个功能需要更新版本才能运行。我尝试使用自定义类加载器来解决这个类路径地狱。经过一番谷歌搜索并在以前的一些 Stackoverflow 答案[1] [2]和本博客的帮助下,我编写了以下Parent Last Class loader ,在委托给父类加载器之前从较新的 jar 中加载类。
public class ParentLastClassLoader extends ClassLoader {
private String jarFile; //Path to the jar file
private Hashtable classes = new Hashtable(); //used to cache already defined classes
public ParentLastClassLoader(ClassLoader parent, String path)
{
super(parent);
this.jarFile = path;
}
@Override
public Class<?> findClass(String name) throws ClassNotFoundException
{
System.out.println("Trying to find");
throw new ClassNotFoundException();
}
@Override
protected synchronized Class<?> loadClass(String className, boolean …Run Code Online (Sandbox Code Playgroud) 抱歉,如果之前有人问过这个问题——如果有的话,我显然是在寻找错误的东西。这不是我第一次被 java、eclipse 以及它们如何找到源文件所困扰。
我有一个 Java 源文件夹,我希望将它们复制到“src/com”文件夹中,并使其“正常工作”。如果我直接复制文件,eclipse 和 java 无法识别它们,所以我假设某处有一个文件告诉 IDE 那里有一个包含在项目中的文件文件夹。我想知道如何通过配置文件和 IDE UI 来做到这一点。
不幸的是,两个明显的文件(.project 和 .classpath)似乎根本没有引用现有目录(.classpath 包含一行
<classpathentry kind="src" path="src"/>
我认为会自动扫描该目录中的文件,但它似乎没有)
最后,.classpath 和.project 是java概念还是eclipse概念?
感谢您的时间。
你好,我在 Linux 上的 Tomcat 服务器中有一个 web 应用程序
我需要能够告诉它以什么顺序加载位于 WEB-INF/bin 中的 jar。我尝试在 Class-Path 下的 META-INF/MANIFEST.MF 中设置它,但它不起作用,我在网上搜索了解决方案,但没有找到任何解决方案。
(我的项目不在war文件中)
(将jar文件名改为“aaaaaaaRealName.jar”的解决方案是不可接受的)
(我正在使用 Tomcat 7(我认为它是 v7.0.27))
我愿意
当我尝试更改 css 文件所在的文件夹时,出现此错误:
WARNING: com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged Resource "file:/C:/[path-to-project]/Test/resources/css/main.css" not found.
Run Code Online (Sandbox Code Playgroud)
我复制了 URL 并将其粘贴到文件管理器中,然后它打开了文件,所以我知道它存在。
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
primaryStage.setTitle("New Window");
Scene scene = new Scene(new AnchorPane(), 800, 600);
primaryStage.setScene(scene);
URL css = new URL("file:///" +
new File("resources/css").getAbsolutePath().replace("\\", "/") +
"/main.css");
scene.getStylesheets().clear();
scene.getStylesheets().add(css.toExternalForm());
primaryStage.show();
}
Run Code Online (Sandbox Code Playgroud)
这是我的 Eclipse 项目布局[也作为图像]:
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
primaryStage.setTitle("New Window");
Scene scene …Run Code Online (Sandbox Code Playgroud) 我已经将Java安装到Windows环境下的默认文件夹中。
然而,我没有管理员访问权限。如何将安全证书添加到jre/lib/security路径中的cacerts文件中?如果无法编辑此文件,我可以将 cacerts 文件复制到其他位置并将其添加到类路径吗?
我application.conf在src/main/resources默认加载的文件夹中有一个类型安全配置。
可以通过指定来覆盖单个值:
--conf spark.driver.extraJavaOptions=-DsomeValue="foo"
Run Code Online (Sandbox Code Playgroud)
但是,指定一个全新的,即覆盖application.conf文件,如:
spark-submit \
--class my.Class \
--master "local[2]" \
--files foo.conf \
--conf spark.driver.extraClassPath="-Dconfig.file=file:foo.conf" \
--conf spark.driver.extraJavaOptions=-Dvalue="abcd" \
job.jar
Run Code Online (Sandbox Code Playgroud)
将无法加载foo.conf。相反,将加载资源文件夹中的原始文件。尝试以下技巧:在 Yarn 上使用带有 Spark 的类型安全配置也没有帮助。
在使用 uberjar 进行部署时覆盖 Typesafe 配置中的多个配置值似乎是普通(无火花)程序的答案。问题仍然是如何激发这一点。
还通过:
--conf spark.driver.extraClassPath="-Dconfig.resource=file:foo.conf"
--conf spark.driver.extraClassPath="-Dconfig.resource=foo.conf"
Run Code Online (Sandbox Code Playgroud)
无法从命令行加载我的配置。
不过,根据文档:
https://github.com/lightbend/config对于使用 application.{conf,json,properties} 的应用程序,系统属性可用于强制不同的配置源(例如从命令行 -Dconfig.file=path/to/config -文件):
- config.resource 指定资源名称 - 不是基本名称,即 application.conf 不是应用程序
- config.file 指定文件系统路径,同样它应该包含扩展名,而不是基本名称
- config.url 指定一个 URL
这些系统属性指定了 application.{conf,json,properties} 的替代品,而不是附加品。它们仅影响使用默认 ConfigFactory.load() 配置的应用程序。在替换配置文件中,您可以使用 include "application" 来包含原始默认配置文件;在包含语句之后,您可以继续覆盖某些设置。
应该可以使用这些参数。
使用java,我可以从application.properties文件中获取“spring.datasource.url”键的值,如下所示:
@PropertySource("classpath:application.properties")
public class SpringJdbcConfig {
@Autowired
Environment environment;
private final String URL = "spring.datasource.url";
String dburl = environment.getProperty("spring.datasource.url");
}
Run Code Online (Sandbox Code Playgroud)
使用 kotlin,这是不可能的:
@PropertySource("classpath:application.properties")
open class WebController {
@Autowired
var env: Environment ? = null
}
Run Code Online (Sandbox Code Playgroud)
环境不会引用 PropertySource 文件。我如何在 kotlin 中使用它?
我有一个小的 Spring Boot 应用程序,它在 src/main/resources 中提供了一个 application.properties - 这就像一个魅力。用户现在应该能够配置更多内容(2 个凭据),因此我期望类路径中有一个名为“matrixregistration.config”的文件。不幸的是,无论在哪里都找不到这个文件。该应用程序通过 gradle spring boot 任务 bootDistZip 进行分发。
@Configuration
@PropertySource("classpath:matrixregistration.config")
@Validated
public class MatrixRegistrationConfiguration {
private String sharedSecret;
private String registrationPassword;
...
Run Code Online (Sandbox Code Playgroud)
我的分发包位于服务器上的 /home/matrix/matrixregistration-boot 上,有一个“bin”和一个“lib”文件夹。我希望当我将配置放入此目录并使用 ./bin/matrixregistration 启动应用程序时,类路径应包含“.” 并找到配置。但事实并非如此。配置文件就在那里。
例外情况:
matrix@myhost:~/matrixregistration-boot$ ./bin/matrixregistration
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | …Run Code Online (Sandbox Code Playgroud) classpath ×10
java ×6
properties ×2
apache-spark ×1
binding ×1
bouncycastle ×1
certificate ×1
classloader ×1
css ×1
eclipse ×1
jakarta-ee ×1
javafx ×1
kotlin ×1
rad ×1
security ×1
spring-boot ×1
tomcat ×1