简体   繁体   中英

Java class not compiling working outside of netbeans with maven dependicies

I have create a project in Java. I added a maven dependency, nimbus-jose-jwt.

My pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<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.mycompany</groupId>
  <artifactId>vertxTestProject</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <vertx.version>3.0.0-milestone4</vertx.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-core</artifactId>
      <version>${vertx.version}</version>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-apex</artifactId>
      <version>${vertx.version}</version>
    </dependency>
    <!-- Uncomment if you want to enable clustering with Hazelcast
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-hazelcast</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <!-- Uncomment if you want to use the async database service
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-mysql-postgresql-service</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <!-- Uncomment if you want to enable async mail sending service
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-mail-service</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <!-- Uncomment if you want to enable reactive streams
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-reactive-streams</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <!-- Uncomment if you want to enable mongo DB service
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-mongo-service</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <!-- Uncomment if you want to enable metrics
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-dropwizard-metrics</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <!-- Uncomment if you want to enable the JDBC database service
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-jdbc-service</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <!-- Uncomment if you want to enable the auth service
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-auth-service</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <!-- Uncomment if you want to use the RxJava API for Vert.x
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-rx-java</artifactId>
        <version>${vertx.version}</version>
    </dependency>-->
    <dependency>
      <groupId>com.restfb</groupId>
      <artifactId>restfb</artifactId>
      <version>1.10.1</version>
    </dependency>
    <dependency>
      <groupId>com.nimbusds</groupId>
      <artifactId>nimbus-jose-jwt</artifactId>
      <version>3.10</version>
      <type>jar</type>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>io.vertx.core.Starter</Main-Class>
                    <Main-Verticle>com.mycompany.vertxtestproject.Main</Main-Verticle>
                  </manifestEntries>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
                </transformer>
              </transformers>
              <artifactSet></artifactSet>
              <outputFile>${project.build.directory}/vertxTestProject-${project.version}-fat.jar</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.3.2</version>
        <executions>
          <execution>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>io.vertx.core.Starter</mainClass>
          <additionalClasspathElements>
            <additionalClasspathElement>${basedir}/src/main/java</additionalClasspathElement>
          </additionalClasspathElements>
          <systemProperties>
            <systemProperty>
              <key>vertx.deployment.options.redeploy</key>
              <value>true</value>
            </systemProperty>
            <systemProperty>
              <key>vertx.deployment.options.redeployScanPeriod</key>
              <value>100</value>
            </systemProperty>
          </systemProperties>
          <arguments>
            <argument>run</argument>
            <argument>com/mycompany/vertxtestproject/Main.java</argument>
            <!--                  <argument>-cluster</argument>
            <argument>-cluster-host</argument>
            <argument>127.0.0.1</argument>-->
          </arguments>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

When I run inside of netbeans everything compiles and runs. When I clean and build and try to run through command line I get the error that:

error: package com.nimbusds.jose does not exist

This is the first time I have used maven so I am very new to this.

You have maven-shade-plugin in your pom file, it creates a single executable "fat" jar with all of the dependencies merged. So after you execute maven clean and package goals, you should run this jar from the command line like this:

java -jar target/vertxTestProject-1.0-SNAPSHOT-fat.jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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