load file within a jar

本文介绍如何使用Java从JAR文件中读取文本文件和其他资源,提供了多个示例,包括使用getClass().getResourceAsStream()方法直接读取资源,以及通过File和URI方式访问资源。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

String examplejsPrefix = "example";
String examplejsSuffix = "js";
String examplejs = examplejsPrefix + "." + examplejsSuffix;

try {

// save it as a temporary file so the JVM will handle creating it and deleting
File file = File.createTempFile(examplejsPrefix, examplejsSuffix);
file.deleteOnExit();
OutputStream out = new FileOutputStream(file);

InputStream in = getClass().getResourceAsStream("/com/" + examplejs);
int len = 0;
byte[] buffer = new byte[1024];
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}

===============

https://alvinalexander.com/blog/post/java/read-text-file-from-jar-file

 

Java jar file reading FAQ: Can you show me how a Java application can read a text file from own of its own Jar files?

Here's an example of some Java code I'm using to read a file (a text file) from a Java Jar file. This is useful any time you pack files and other resources into Jar files to distribute your Java application.

How to read a Java Jar file, example #1

The source code to read a file from a Java Jar file uses the getClass and getResourceAsStream methods:

  public void test3Columns()
  throws IOException
  {
    InputStream is = getClass().getResourceAsStream("3Columns.csv");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;
    while ((line = br.readLine()) != null) 
    {
      CSVLineTokenizer tok = new CSVLineTokenizer(line);
      assertEquals("Should be three columns in each row",3,tok.countTokens());
    }
    br.close();
    isr.close();
    is.close();
  }

The trick to reading text files from JAR files are these lines of code, especially the first line:

InputStream is = getClass().getResourceAsStream("3Columns.csv");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);

In my example I have a plain text file named "3Columns.csv" in the same directory as the class that contains this method. Without a path stated before the filename (like "/foo/bar/3Columns.csv") the getResourceAsStreammethod looks for this text file in its current directory.

 

Note that I'm doing all of this within the context of a JUnit test method. Also note that I'm throwing any exceptions that occur rather than handling them. I don't recommend this for real world programming, but it works okay for my unit testing needs today.

I haven't read through the Javadocs yet to know if all of those closestatements at the end are necessary. I'll try to get back to that later.

Java: How to read a Jar file, example #2

Here is a slightly more simple version of that method:

public String readFromJARFile(String filename)
throws IOException
{
  InputStream is = getClass().getResourceAsStream(filename);
  InputStreamReader isr = new InputStreamReader(is);
  BufferedReader br = new BufferedReader(isr);
  StringBuffer sb = new StringBuffer();
  String line;
  while ((line = br.readLine()) != null) 
  {
    sb.append(line);
  }
  br.close();
  isr.close();
  is.close();
  return sb.toString();
}

In this sample I've eliminated the CSVLineTokenizer and replaced it with a simple StringBuffer, and I return a plain old String at the end of the method.

Also, if I didn't stress it properly earlier, with this approach the resource file that you're trying to read from must be in the same directory in the jar file as this class. This is inferred by the getClass().getResourceAsStream()method call, but I don't think I really stressed that enough earlier.

Also, I haven't looked at it in a while, but I think you can just call the is.close() method to close all your resources, you don't have to make all the close calls I make here, but I'm not 100% positive.

Reading a file from a jar file as a File

Here's one more example of how to do this, this time using some code from a current Scala project:

val file = new File(getClass.getResource("zipcode_data.csv").toURI)

Although the code shown is Scala, I think you can see that you can use this approach to read the file as a java.io.File instead of reading it as a stream.

One more Java "read from Jar file" example

While I'm working on another Java project, I just ran across another example of how to read a file from a Java jar file in this method:

private void playSound(String soundfileName)
{
  try
  {
    ClassLoader CLDR = this.getClass().getClassLoader();
    InputStream inputStream = CLDR.getResourceAsStream("com/devdaily/desktopcurtain/sounds/" + soundfileName);
    AudioStream audioStream = new AudioStream(inputStream);
    AudioPlayer.player.start(audioStream);
  }
  catch (Exception e)
  {
    // log this
  }
}

As you can guess from looking at this code, this example shows how to read a resource file from a jar file in a java application, and in this approach, the resource file that I'm reading doesn't have to be in the same directory as the Java class file. As you can imagine, this is a much more flexible approach.

转载于:https://www.cnblogs.com/kungfupanda/p/9472064.html

18:00:32,438 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [CONFIG_LOG_FILE] 18:00:32,439 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 18:00:32,464 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@366d8b97 - No compression will be used 18:00:32,467 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 18:00:32,483 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - Active log file name: /root/logs/nacos/config.log 18:00:32,483 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - File property is set to [/root/logs/nacos/config.log] 18:00:32,484 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [ASYNC-CONFIG] 18:00:32,484 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender] 18:00:32,486 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [CONFIG_LOG_FILE] to ch.qos.logback.classic.AsyncAppender[ASYNC-CONFIG] 18:00:32,487 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-CONFIG] - Attaching appender named [CONFIG_LOG_FILE] to AsyncAppender. 18:00:32,487 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-CONFIG] - Setting discardingThreshold to 0 18:00:32,487 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [NAMING_LOG_FILE] 18:00:32,487 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 18:00:32,488 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@feb98ef - No compression will be used 18:00:32,488 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 18:00:32,489 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[NAMING_LOG_FILE] - Active log file name: /root/logs/nacos/naming.log 18:00:32,489 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[NAMING_LOG_FILE] - File property is set to [/root/logs/nacos/naming.log] 18:00:32,489 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [ASYNC-NAMING] 18:00:32,489 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender] 18:00:32,489 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [NAMING_LOG_FILE] to ch.qos.logback.classic.AsyncAppender[ASYNC-NAMING] 18:00:32,489 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-NAMING] - Attaching appender named [NAMING_LOG_FILE] to AsyncAppender. 18:00:32,489 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-NAMING] - Setting discardingThreshold to 0 18:00:32,489 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [REMOTE_LOG_FILE] 18:00:32,489 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 18:00:32,490 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@7654f833 - No compression will be used 18:00:32,490 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 18:00:32,490 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[REMOTE_LOG_FILE] - Active log file name: /root/logs/nacos/remote.log 18:00:32,490 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[REMOTE_LOG_FILE] - File property is set to [/root/logs/nacos/remote.log] 18:00:32,491 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [ASYNC-REMOTE] 18:00:32,491 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender] 18:00:32,491 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [REMOTE_LOG_FILE] to ch.qos.logback.classic.AsyncAppender[ASYNC-REMOTE] 18:00:32,491 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-REMOTE] - Attaching appender named [REMOTE_LOG_FILE] to AsyncAppender. 18:00:32,491 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-REMOTE] - Setting discardingThreshold to 0 18:00:32,491 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [com.alibaba.nacos.client] to INFO 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting additivity of logger [com.alibaba.nacos.client] to false 18:00:32,494 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [ASYNC-CONFIG] to Logger[com.alibaba.nacos.client] 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [com.alibaba.nacos.common.labels] to INFO 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting additivity of logger [com.alibaba.nacos.common.labels] to false 18:00:32,494 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [ASYNC-REMOTE] to Logger[com.alibaba.nacos.common.labels] 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [com.alibaba.nacos.common.remote.client] to INFO 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting additivity of logger [com.alibaba.nacos.common.remote.client] to false 18:00:32,494 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [ASYNC-REMOTE] to Logger[com.alibaba.nacos.common.remote.client] 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [com.alibaba.nacos.shaded.io.grpc] to INFO 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting additivity of logger [com.alibaba.nacos.shaded.io.grpc] to false 18:00:32,494 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [ASYNC-REMOTE] to Logger[com.alibaba.nacos.shaded.io.grpc] 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [com.alibaba.nacos.client.config] to INFO 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting additivity of logger [com.alibaba.nacos.client.config] to false 18:00:32,494 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [ASYNC-CONFIG] to Logger[com.alibaba.nacos.client.config] 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [com.alibaba.nacos.client.naming] to INFO 18:00:32,494 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting additivity of logger [com.alibaba.nacos.client.naming] to false 18:00:32,494 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [ASYNC-NAMING] to Logger[com.alibaba.nacos.client.naming] 18:00:32,494 |-INFO in ch.qos.logback.core.model.processor.DefaultProcessor@571a01f9 - End of configuration. 18:00:32,495 |-INFO in com.alibaba.nacos.logbackadapter.NacosLogbackConfiguratorAdapterV2@42f33b5d - Registering current configuration as safe fallback point 18:00:33,840 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-CONFIG] - Worker thread will flush remaining events before exiting. 18:00:33,841 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-CONFIG] - Queue flush finished successfully within timeout. 18:00:33,841 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-NAMING] - Worker thread will flush remaining events before exiting. 18:00:33,841 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-NAMING] - Queue flush finished successfully within timeout. 18:00:33,841 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-REMOTE] - Worker thread will flush remaining events before exiting. 18:00:33,841 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC-REMOTE] - Queue flush finished successfully within timeout. 18:00:33,847 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@d7109be - URL [jar:nested:/app/workflow.jar/!BOOT-INF/classes/!/logback-plus.xml] is not of type file 18:00:33,855 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@5e0ec41f - Adding [jar:nested:/app/workflow.jar/!BOOT-INF/lib/ruoyi-common-web-2.2.1.jar!/logback-common.xml] to configuration watch list. 18:00:33,855 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@d7109be - URL [jar:nested:/app/workflow.jar/!BOOT-INF/lib/ruoyi-common-web-2.2.1.jar!/logback-common.xml] is not of type file 18:00:33,863 |-WARN in ch.qos.logback.core.joran.action.IncludeAction - Could not find resource corresponding to [logback-logstash.xml] 18:00:33,864 |-WARN in ch.qos.logback.core.joran.action.IncludeAction - Could not find resource corresponding to [logback-skylog.xml] 18:00:33,869 |-INFO in ch.qos.logback.classic.model.processor.ConfigurationModelHandlerFull - Registering a new ReconfigureOnChangeTask ReconfigureOnChangeTask(born:1749722433867) 18:00:33,869 |-INFO in ch.qos.logback.classic.model.processor.ConfigurationModelHandlerFull - Will scan for changes in [jar:nested:/app/workflow.jar/!BOOT-INF/classes/!/logback-plus.xml] 18:00:33,869 |-INFO in ch.qos.logback.classic.model.processor.ConfigurationModelHandlerFull - Setting ReconfigureOnChangeTask scanning period to 1 minutes 18:00:33,870 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [console] 18:00:33,870 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 18:00:33,870 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 18:00:33,872 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [file_console] 18:00:33,872 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 18:00:33,873 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@256522893 - No compression will be used 18:00:33,874 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@256522893 - Will use the pattern logs/ruoyi-workflow/console.%d{yyyy-MM-dd}.log for the active file 18:00:33,883 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'logs/ruoyi-workflow/console.%d{yyyy-MM-dd}.log'. 18:00:33,883 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight. 18:00:33,883 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to 2025-06-12T10:00:33.883Z 18:00:33,884 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 18:00:33,888 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file_console] - Active log file name: logs/ruoyi-workflow/console.log 18:00:33,888 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file_console] - File property is set to [logs/ruoyi-workflow/console.log] 18:00:33,888 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [file_info] 18:00:33,888 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 18:00:33,888 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@148436820 - No compression will be used 18:00:33,888 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@148436820 - Will use the pattern logs/ruoyi-workflow/info.%d{yyyy-MM-dd}.log for the active file 18:00:33,889 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'logs/ruoyi-workflow/info.%d{yyyy-MM-dd}.log'. 18:00:33,889 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight. 18:00:33,889 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to 2025-06-12T10:00:33.889Z 18:00:33,889 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 18:00:33,891 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file_info] - Active log file name: logs/ruoyi-workflow/info.log 18:00:33,891 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file_info] - File property is set to [logs/ruoyi-workflow/info.log] 18:00:33,891 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [file_error] 18:00:33,891 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 18:00:33,892 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@224473864 - No compression will be used 18:00:33,892 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@224473864 - Will use the pattern logs/ruoyi-workflow/error.%d{yyyy-MM-dd}.log for the active file 18:00:33,892 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'logs/ruoyi-workflow/error.%d{yyyy-MM-dd}.log'. 18:00:33,892 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight. 18:00:33,893 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to 2025-06-12T10:00:33.893Z 18:00:33,893 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 18:00:33,893 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file_error] - Active log file name: logs/ruoyi-workflow/error.log 18:00:33,893 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file_error] - File property is set to [logs/ruoyi-workflow/error.log] 18:00:33,894 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [async_info] 18:00:33,894 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender] 18:00:33,894 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [file_info] to ch.qos.logback.classic.AsyncAppender[async_info] 18:00:33,894 |-INFO in ch.qos.logback.classic.AsyncAppender[async_info] - Attaching appender named [file_info] to AsyncAppender. 18:00:33,894 |-INFO in ch.qos.logback.classic.AsyncAppender[async_info] - Setting discardingThreshold to 0 18:00:33,894 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [async_error] 18:00:33,894 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender] 18:00:33,894 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [file_error] to ch.qos.logback.classic.AsyncAppender[async_error] 18:00:33,894 |-INFO in ch.qos.logback.classic.AsyncAppender[async_error] - Attaching appender named [file_error] to AsyncAppender. 18:00:33,894 |-INFO in ch.qos.logback.classic.AsyncAppender[async_error] - Setting discardingThreshold to 0 18:00:33,895 |-INFO in ch.qos.logback.classic.model.processor.RootLoggerModelHandler - Setting level of ROOT logger to INFO 18:00:33,895 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@25673087 - Propagating INFO level on Logger[ROOT] onto the JUL framework 18:00:33,895 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [async_info] to Logger[ROOT] 18:00:33,895 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [async_error] to Logger[ROOT] 18:00:33,895 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [file_console] to Logger[ROOT] 18:00:33,895 |-INFO in ch.qos.logback.classic.model.processor.RootLoggerModelHandler - Setting level of ROOT logger to INFO 18:00:33,895 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [console] to Logger[ROOT] 18:00:33,896 |-INFO in ch.qos.logback.core.model.processor.DefaultProcessor@7b27e8f4 - End of configuration. 18:00:33,896 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@348ad293 - Registering current configuration as safe fallback point :: Dubbo (v3.2.14) : https://github.com/apache/dubbo :: Discuss group : dev@dubbo.apache.org Spring Boot Version: 3.2.9 Spring Application Name: ruoyi-workflow _ _ __ _ (_) | | / _| | _ __ _ _ ___ _ _ _ ________ _____ _ __| | _| |_| | _____ __ | '__| | | |/ _ \| | | | |______\ \ /\ / / _ \| '__| |/ / _| |/ _ \ \ /\ / / | | | |_| | (_) | |_| | | \ V V / (_) | | | <| | | | (_) \ V V / |_| \__,_|\___/ \__, |_| \_/\_/ \___/|_| |_|\_\_| |_|\___/ \_/\_/ __/ | |___/ 2025-06-12 18:00:34 [main] INFO  o.d.w.RuoYiWorkflowApplication  - Starting RuoYiWorkflowApplication using Java 17.0.2 with PID 1 (/app/workflow.jar started by root in /app) 2025-06-12 18:00:34 [main] INFO  o.d.w.RuoYiWorkflowApplication  - The following 1 profile is active: "prod" 2025-06-12 18:00:34 [main] INFO  c.a.c.n.c.NacosConfigDataLoader  - [Nacos Config] Load config[dataId=ruoyi-workflow.yml, group=ARCHIVES] success 2025-06-12 18:00:34 [main] INFO  c.a.c.n.c.NacosConfigDataLoader  - [Nacos Config] Load config[dataId=datasource.yml, group=ARCHIVES] success 2025-06-12 18:00:34 [main] INFO  c.a.c.n.c.NacosConfigDataLoader  - [Nacos Config] Load config[dataId=application-common.yml, group=ARCHIVES] success 2025-06-12 18:00:41 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext  - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server 2025-06-12 18:00:41 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter  - *************************** APPLICATION FAILED TO START *************************** Description: Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context. Action: Check your application's dependencies for a supported servlet web server. Check the configured web application type. 2025-06-12 18:00:41 [Thread-6] WARN  c.a.nacos.common.notify.NotifyCenter  - [NotifyCenter] Start destroying Publisher 2025-06-12 18:00:41 [Thread-6] WARN  c.a.nacos.common.notify.NotifyCenter  - [NotifyCenter] Destruction of the end 2025-06-12 18:00:41 [Thread-4] WARN  c.a.n.c.http.HttpClientBeanHolder  - [HttpClientBeanHolder] Start destroying common HttpClient 2025-06-12 18:00:41 [Thread-4] WARN  c.a.n.c.http.HttpClientBeanHolder  - [HttpClientBeanHolder] Destruction of the end 分析日志给出解决办法 需要nacos如何配置
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值