How to Configure Class Paths from VM Arguments in Eclipse

Asked 2 years ago, Updated 2 years ago, 135 views

I have a question about eclipse.

properties file in external folder I'd like to load it.

from the VM argument in eclipse Java Build Path > Library > Class Path
Is there a way to set up an external folder?

Thank you for your cooperation.

Supplemental

because I read messages.properties values directly into html using Thymeleaf. I want to add an external directory to the class path.

java eclipse spring-boot tomcat

2022-09-30 21:49

1 Answers

When running from Eclipse (STS), "Java Build Path > Library > Class Path External Folder" allows you to read external messages.properties, but is this the question intended to specify when running with the java-jar<spring-boot app > command?

The location of the message source (resource bundle) is specified by spring.massages.basename, where you can also specify a file (base name) on the file system ( file: ).align i18n properties files in spring-boot applications-Stack Overflow).

Property settings can also be specified with command-line arguments (4.2.2.Accessing Command Line Properties).

Therefore, if ./external-resources/messages.properties is the file you want to read,

java-jar<spring-boot app>.jar --spring.messages.basename=file:external-resources/messages

available on the .

Execution sample code , war version

using Thymeleaf

When deploying to Tomcat, Tomcat needs to be directed.Learn more about how to configure:

Tomcat9 deploys the aforementioned war and reads the message resources under the /tmp/external-resources directory.

  • Move the messages.properties file under the /tmp/external-resources/ directory
  • Create a conf/Catalina/localhost/demo-0.0.1-SNAPSHOT.xml file under Tomcat's main body.Includes:
<Context>
  <Resources>
    <PostResources
      className="org.apache.catalina.webresources.DirResourceSet"
      base="/tmp/external-resources"
      webAppMount="/WEB-INF/classes"/>
  </Resources>
</Context>

With this configuration, the /tmp/external-resources directory is inserted into the war file /WEB-INF/classes so that applications can find message resources in the class path.


2022-09-30 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.