简体   繁体   English

Maven安装后缺少类

[英]Missing Class after Maven Install

So I've pretty much been banging my head against the wall trying to solve this one... 所以我几乎已经把头撞在墙上,试图解决这个问题...

This is my first time using Maven, and am using it on OSX to install the ews-java-api. 这是我第一次使用Maven,并且正在OSX上使用它来安装ews-java-api。

After clean, or instal, and everything builds successfully, but I am still unable to access the classes through a java file. 清理或安装后,一切都可以成功构建,但是我仍然无法通过Java文件访问这些类。

I'm getting the following errors, 我遇到以下错误,

    Connect.java:3: error: package microsoft.exchange.webservices.data does not exist
    import microsoft.exchange.webservices.data.*;
    Connect.java:15: error: cannot find symbol
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
    ^
    symbol:   class ExchangeService
    location: class Connect

I'm curious if I've overall made a mistake with the install path, when installing Maven... or if theres another issue regarding where I'm downloading the API package? 我很好奇我是否总体上在安装Maven时安装路径有误...或者在我的API包下载位置是否还有其他问题?

Any help is much appreciated!! 任何帮助深表感谢!!

[EDIT] This is my bash.profile output... [编辑]这是我的bash.profile输出...

    $ cat ~/.bash_profile 
    export M2_HOME=/Users/joliv64/mailtests/apache-maven-3.3.3/
    export PATH=$PATH:$M2_HOME/bin

Also this is 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.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>

<version>3.0-SNAPSHOT</version>

<name>Exchange Web Services Java API</name>
<description>Exchange Web Services (EWS) Java API</description>

<!-- Required by the site command for certain relative URL configuration. -->
<url>http://www.microsoft.com/</url>

<!-- Used by the javadoc plugin to generate the comments at the bottom. -->
<inceptionYear>2012</inceptionYear>

<!-- Used to define a minimum Maven version. Used in conjunction with plugin
    management to lock in a more current version of the various plugins. -->
<prerequisites>
    <maven>3.1.0</maven>
</prerequisites>

<organization>
    <name>Microsoft</name>
    <url>http://www.microsoft.com/</url>
</organization>

<properties>
    <!-- Eliminates the file encoding warning. Of course, all of your files
        should probably be UTF-8 nowadays. -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <javaLanguage.version>1.6</javaLanguage.version>
    <javadoc.doclint.param/>

    <!--  Dependencies [BUILD]:  -->
    <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
    <maven-javadoc-plugin.version>2.10.3</maven-javadoc-plugin.version>
    <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
    <nexus-staging-maven-plugin.version>1.6.5</nexus-staging-maven-plugin.version>
    <maven-source-plugin.version>2.4</maven-source-plugin.version>
    <animal-sniffer-maven-plugin.version>1.14</animal-sniffer-maven-plugin.version>
    <animal-sniffer-maven-plugin.signature.version>1.1</animal-sniffer-maven-plugin.signature.version>
    <!--  Dependencies [REPORT]:  -->
    <maven-site-plugin.version>3.4</maven-site-plugin.version>
    <maven-project-info-reports-plugin.version>2.8</maven-project-info-reports-plugin.version>
    <versions-maven-plugin.version>2.2</versions-maven-plugin.version>
    <maven-jxr-plugin.version>2.5</maven-jxr-plugin.version>
    <maven-surefire-report-plugin.version>2.18.1</maven-surefire-report-plugin.version>
    <!--  Dependencies [COMPILE]:  -->
    <httpclient.version>4.4.1</httpclient.version>
    <httpcore.version>4.4.1</httpcore.version>
    <commons-logging.version>1.2</commons-logging.version>
    <joda-time.version>2.8</joda-time.version>
    <commons-lang3.version>3.4</commons-lang3.version>
    <!--  Dependencies [TEST]:  -->
    <junit.version>4.12</junit.version>
    <hamcrest-all.version>1.3</hamcrest-all.version>
    <mockito-core.version>1.10.19</mockito-core.version>
    <slf4j.version>1.7.12</slf4j.version>
    <logback.version>1.1.3</logback.version>
</properties>

<profiles>
    <profile>
        <!-- handle broken builds on jdk1.8 due to doclint function -->
        <id>default-jdk18-profile</id>
        <activation>
            <jdk>[1.8,)</jdk>
        </activation>
        <properties>
            <javadoc.doclint.param>-Xdoclint:none</javadoc.doclint.param>
        </properties>
    </profile>
    <profile>
        <id>release-sign-artifacts</id>
        <activation>
            <property>
                <name>gpg.passphrase</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>${maven-gpg-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

<licenses>
    <license>
        <name>MIT License</name>
        <url>http://opensource.org/licenses/MIT</url>
        <distribution>repo</distribution>
    </license>
</licenses>

<issueManagement>
    <url>https://github.com/OfficeDev/ews-java-api/issues</url>
    <system>GitHub Issues</system>
</issueManagement>

<ciManagement>
    <system>travis</system>
    <url>https://travis-ci.org/OfficeDev/ews-java-api</url>
</ciManagement>

<scm>
    <url>https://github.com/OfficeDev/ews-java-api</url>
    <connection>scm:git:ssh://git@github.com:OfficeDev/ews-java-api.git</connection>
    <developerConnection>scm:git:ssh://git@github.com:OfficeDev/ews-java-api.git</developerConnection>
</scm>

<distributionManagement>
    <snapshotRepository>
        <id>ossrh-snapshot</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
        <id>ossrh</id>
        <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>

    </repository>
</distributionManagement>

<dependencies>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${httpclient.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>${httpcore.version}</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>${commons-logging.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons-lang3.version}</version>
    </dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>${joda-time.version}</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>${hamcrest-all.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>${mockito-core.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${slf4j.version}</version>
        <scope>test</scope>
    </dependency>

<!-- Added Dependency -->
<dependency>
        <groupId>com.microsoft.ews-java-api</groupId>
        <artifactId>ews-java-api</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <!-- Deployment / build plugins -->
        <plugin>
            <groupId>org.sonatype.plugins</groupId>
            <artifactId>nexus-staging-maven-plugin</artifactId>
            <version>${nexus-staging-maven-plugin.version}</version>
            <extensions>true</extensions>
            <configuration>
                <!-- Ref.: http://books.sonatype.com/nexus-book/reference/staging-deployment.html -->
                <autoReleaseAfterClose>true</autoReleaseAfterClose>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <encoding>${project.build.sourceEncoding}</encoding>
                <source>${javaLanguage.version}</source>
                <target>${javaLanguage.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>${maven-javadoc-plugin.version}</version>
            <configuration>
                <linksource>true</linksource>
                <additionalparam>${javadoc.doclint.param}</additionalparam>
            </configuration>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>${maven-source-plugin.version}</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>animal-sniffer-maven-plugin</artifactId>
            <version>${animal-sniffer-maven-plugin.version}</version>
            <configuration>
                <signature>
                    <groupId>org.codehaus.mojo.signature</groupId>
                    <artifactId>java16-sun</artifactId>
                    <version>${animal-sniffer-maven-plugin.signature.version}</version>
                </signature>
            </configuration>
            <executions>
                <execution>
                    <id>check-java16-sun</id>
                    <phase>test</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- Deployment / build plugins END -->
    </plugins>
    <!-- Used to bump all of the various core plugins up to Maven current.
        Use this in conjunction with the versions-maven-plugin to keep your Maven
        plugins up to date. -->
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>${maven-site-plugin.version}</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<reporting>
    <plugins>
        <!-- Basic report generation. -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>${maven-project-info-reports-plugin.version}</version>
        </plugin>

        <!-- Dependency version reporting. Relies on standard version numbering
            - you should use standard version numbering too!
            http://mojo.codehaus.org/versions-maven-plugin/version-rules.html -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>${versions-maven-plugin.version}</version>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>dependency-updates-report</report>
                        <report>plugin-updates-report</report>
                        <report>property-updates-report</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>

        <!-- Generates the Javadoc for the report. -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>${maven-javadoc-plugin.version}</version>
            <configuration>
                <linksource>true</linksource>
                <additionalparam>${javadoc.doclint.param}</additionalparam>
            </configuration>
        </plugin>

        <!-- Generates a nice HTML linked source cross-reference. -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jxr-plugin</artifactId>
            <version>${maven-jxr-plugin.version}</version>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>${maven-surefire-report-plugin.version}</version>
        </plugin>
    </plugins>
</reporting>
      <repositories>
<repository>
  <id>sonatype-snapshots</id>
  <name>Sonatype OSS Snapshots</name>
  <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
  <releases>
    <enabled>false</enabled>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>

Two suspected areas we can have as mentioned in the Comments. 如评论中所述,我们可以拥有两个可疑区域。

  1. Either you don't have dependency for Jar contains the mentioned class. 您可能没有依赖关系,因为Jar包含上述类。
  2. Or If its present then problem is with the .classpath file. 或如果存在,则问题在于.classpath文件。

@user1933888/ @Ferdinand Neman/ @Subodh Joshi are very right. @ user1933888 / @Ferdinand Neman / @Subodh Joshi非常正确。

@Zavael- By default scope is compile need not to define explicitly. @Zavael-默认情况下,编译范围不需要显式定义。 REFER: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html 参考: https : //maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

Note: I Don't have right to add comment above so I mentioned here. 注意:我无权在上面添加评论,因此我在这里提到。 I am newbie to this portal:-) 我是该门户网站的新手:-)

So the solution to the problem was much simpler than expected.. 因此,解决该问题的方法比预期的要简单得多。

I was compiling my file with javac, and did not put my class into a package to compile with mvn. 我正在使用javac编译文件,但没有将我的类放入使用mvn进行编译的程序包中。

Also, the imports were a tad off because they were not as advertised from some source code. 另外,导入也有点麻烦,因为它们不像某些源代码所宣传的那样。 So of course mvn was building correctly, I was just trying to access the classes in an incorrect manner. 因此,当然mvn正确构建,我只是试图以错误的方式访问类。

Thanks for the help! 谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM