尝试用JAR构建一个类路径,以便用java-command调用我的程序
我的项目如下所示:
<groupId>com.mysamples</groupId>
<artifactId>mySamples-base</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<revision>1.0.0</revision>
<targetJarDir>E:/$SysProg/mySample/RUN/lib</targetJarDir>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
<modules>
<module>mySamples-frontend</module>
</modules>
<dependencies>
<!-- ***************************************************************************************************
* Springboot *************************************************************************************************** -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- ***************************************************************************************************
* Database Access *************************************************************************************************** -->
<!-- https://mvnrepository.com/artifact/org.codehaus.mojo/jaxb2-maven-plugin -->
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${targetJarDir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<artifactId>mySamples-frontend</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-base</artifactId>
<version>1.0.0</version>
</parent>
<modules>
<module>mySamples-frontend-programs</module>
</modules>
<artifactId>mySamples-frontend-programs</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-frontend</artifactId>
<version>1.0.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.4.RELEASE</version>
<configuration>
<fork>true</fork>
<mainClass>com.mysamples.calling.MainCalling</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<artifactId>mySamples-frontend-programs</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-frontend</artifactId>
<version>1.0.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifestEntries>
<Build-Version>${project.version}</Build-Version>
<Built-By>${user.name}</Built-By>
<Build-Jdk>${java.version}</Build-Jdk>
<Build-Time>${maven.build.timestamp}</Build-Time>
<Build-Number>${buildNumber.value}</Build-Number>
<Build-YearStarted>2020</Build-YearStarted>
<DeveloperName>Ulrich Schmidt</DeveloperName>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我正在运行以下命令:
cd /D .....
SET CLASSPATH=mySamples-frontend-programs-1.0.0.jar
java -Duser.language=en -cp mySamples-frontend-programs-1.0.0.jar com.mysamples.calling.MainCalling
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:467)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:180)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:123)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:434)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:878)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:808)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:779)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.mysamples.calling.MainCalling.main(MainCalling.java:27)
@ComponentScan({"com.mysamples"})
@SpringBootApplication
public class MainCalling {
private static final Logger LOGGER = LoggerFactory.getLogger(MainCalling.class);
@Autowired
public MainCalling(final ClassToBeCalled toBeCalled) {
toBeCalled.isCalled();
}
public static void main(String[] args) {
try {
SpringApplication.run(MainCalling.class);
} catch (Exception e) {
LOGGER.error("", e);
System.exit(-1);
}
}
@Service
public class ClassToBeCalled {
private static final Logger LOGGER = LoggerFactory.getLogger(ClassToBeCalled.class);
public void isCalled() {
LOGGER.info("have been called");
}
}
我想我拿到了。“spring-boot-maven-plugin”不允许使用命令“java-cp${classpath}${chosenMain}”。您必须使用“java-jar${classpath}”--jar的创建方式,只有springframework在jar的rootDir中不能直接调用指定的mainclass。如何调用多个main-class在“使用多个main类运行spring boot”中描述。
感谢@khmarbaise的提示。一开始我不敢相信,但经过一番阅读,我明白了,他是对的。
我有一个连接到MongoDB的项目,配置如下: 另一个项目构建在Spring boot上,配置了Spring security: Spring Boot pom.xml Mongo项目pom.xml 如果我从Spring Boot应用程序到Mongo连接项目中一个接一个地运行,它会正常工作。相反,它会抛出一个错误: org.springframework.beans.factory。未满足的依赖项
我正在使用spring boot开发一个web-app,并在下面给出的application.properties文件中添加了上下文路径,但当我运行应用程序时,它不使用上下文路径。 “我在application.properties文件中添加了#context Path server.port=8085 server.servlet.context-path=/nvs-councellor” “当
问题内容: 任何人都知道为什么该命令在Windows中可以正常工作,但是在Linux中,我得到了ClassNotFoundException game.ui.Main 我的文件夹结构如下:lib /-Jars游戏/-类文件 这是最新的Java 6。 问题答案: 类路径语法与操作系统有关。来自维基百科: 命令行Classpath语法与文件系统密切相关,取决于操作系统。例如: 在所有类似Unix的操作
在这里的Spring Boot文档中,关于服务静态内容,它说: 默认情况下,Spring Boot将从类路径中名为/static(或/public或/resources或/META-INF/resources)的目录提供静态内容。 我发现目录中的所有内容: 将被复制到类路径中,因此我可以将我的静态内容放入: 一切都会很好,我很高兴,因为我可以将我的静态内容放在src目录下。 但是,我对此有一些疑问
我正在用intelliJ IDEA设计一个多模块项目 我的父母Pom: 我的孩子们发出嗡嗡声
我有下面的spring-boot设置,其中包含表单登录和基本auth(部分工作--我可以登录到基本auth,登录表单就会出现)。我只创建了登录表单,因为除非我这样做,否则我甚至无法获得要呈现的登录。 注意:如果有帮助,请在此处完成代码:https://github.com/azeckoski/lti_starter 和我在Thymeleaf的注销表: 但是,登录(和注销)不起作用。 当我试图访问登