[英]Java project compiles with Maven but Eclipse still shows errors
I am new to Maven and an using it to build my Java project. 我是Maven的新手,并且正在使用它来构建我的Java项目。 I have two questions:
我有两个问题:
Here's my pom.xml file: 这是我的pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springhibernate</groupId>
<artifactId>SpringHibernateAssignment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringHibernateAssignment</name>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>com.springhibernate</groupId>
<artifactId>SpringHibernateAssignment</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${basedir}/lib/ojdbc14.jar</file>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-install-plugin
</artifactId>
<versionRange>
[2.4,)
</versionRange>
<goals>
<goal>install-file</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
The m2e plug in for Eclipse will integrate Maven so that Eclipse will automatically include JAR's from the local Maven cache based on the contents of the POM.xml. Eclipse的m2e插件将集成Maven,以便Eclipse将基于POM.xml的内容自动包括来自本地Maven缓存的JAR。
And excluding all Java source files explains why Maven's build succeeds without any dependencies. 并且排除所有Java源文件可以解释为什么Maven的构建在没有任何依赖的情况下能够成功进行。
If those jars you mention are public frameworks, you should be able to find them in the maven central repository and add them to your project just like Eranda explained. 如果您提到的这些jar是公共框架,那么您应该能够在maven中央存储库中找到它们并将其添加到您的项目中,就像Eranda解释的那样。 If you have jars that cannot be found publicly, you have to add them first to your local maven repo using maven install-file plugin: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
如果您有无法公开找到的jar,则必须先使用maven安装文件插件将其添加到本地Maven存储库中: https : //maven.apache.org/guides/mini/guide-3rd-party-jars- local.html
May be your M2_Home is not set, can you confirm. 可能是您的M2_Home未设置,可以确认。 You may be building the project from the command line not from the eclipse ( Guess).
您可能是从命令行而不是从Eclipse(Guess)构建项目。
Suggestions: 1. Set M2_HOME. 建议:1.设置M2_HOME。 2. Clean or Build the Project from eclipse, it will add all your dependent jars to references
2.从eclipse清理或构建项目,它将所有依赖的jar添加到引用中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.