没有编译的Java类在netbeans之外使用maven依赖项工作



我在Java中创建了一个项目。我添加了一个maven依赖,nimbus-jose-jwt。

我的pom.xml文件:

<?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>

当我在netbeans内部运行时,一切都编译并运行。当我清理和构建并尝试通过命令行运行时,我得到的错误是:

error: package com.nimbusds.jose does not exist

这是我第一次使用maven,所以我对这个很陌生。

您的pom文件中有maven-shade-plugin,它创建了一个合并了所有依赖项的可执行的"fat" jar。因此,在执行maven cleanpackage目标之后,您应该像这样从命令行运行这个jar:

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

相关内容

  • 没有找到相关文章

最新更新