这是我的POM.xml文件:
<project>
<properties>
<jdk.version>1.6</jdk.version>
<spring.version>3.2.2.RELEASE</spring.version>
<spring.batch.version>2.2.0.RELEASE</spring.batch.version>
<mysql.driver.version>5.1.25</mysql.driver.version>
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<!-- Spring Core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring jdbc, for database -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring XML to/back object -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.driver.version}</version>
</dependency>
<!-- Spring Batch dependencies -->
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>${spring.batch.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-infrastructure</artifactId>
<version>${spring.batch.version}</version>
</dependency>
<!-- Spring Batch unit test -->
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-test</artifactId>
<version>${spring.batch.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>spring-batch</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>下面是我的java类:
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
public static void main(String[] args) {
String[] springConfig =
{
"spring/batch/jobs/job-hello-world.xml"
};
ApplicationContext context =
new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("helloWorldJob");
try {
JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception e) {
e.printStackTrace();
}
}
}我在我的App.java类中的导入语句中有一个错误,这是一个消息:
“无法解析导入org.springframework。”
我清楚地提到了POM.xml中的依赖项,但我的java类仍然不能从中选择依赖项。
发布于 2013-11-09 02:20:03
您需要遵循几个步骤来正确调试。
1) mvn clean dependency:tree查看输出,看看得到了什么,并验证您的依赖项都在那里。
2) mvn clean compile。这会失败吗?如果不是,这是否意味着您只能在Eclipse中得到错误?
您在评论中提到,“我在上面运行了两个命令,但是我得到了这个错误”。mvn clean compile成功了吗?或者你也犯了错误?如果它成功了,那么它只是一个IDE问题,我会看看m2eclipse插件。更好的是,使用IntelliJ作为免费版本比Eclipse支持更好;)
一些时尚的东西..。
当不需要的时候,人们通常会在他们的pom文件中添加太多的依赖项。如果您查看mavenrepository.com中的几个链接,就会发现spring-oxm和spring-jdbc都依赖于spring-core,因此不需要显式地添加(例如)。mvn clean dependency:tree将向您展示在这一切之后会出现什么,但这更有意义。
spring-batch-test应该是test作用域。
发布于 2013-11-13 01:12:37
我的问题终于解决了。我将项目导入为“已存在的项目到工作区”。这完全是错误的。在那之后,我选择了“现有的Maven项目”,之后,一些小插曲和所有错误都被删除了。在这个过程中,我在Maven中学到了很多东西,它们对于Maven项目中的新comer非常重要。
发布于 2018-07-05 00:38:05
对我有用的解决方案是右键单击项目--> Maven --> Update,然后单击OK。
https://stackoverflow.com/questions/19871437
复制相似问题