Java class 无法在具有 maven 依赖项的 netbeans 之外进行编译
Java class not compiling working outside of netbeans with maven dependicies
我已经在 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 中 运行 时,一切都会编译并且 运行s。当我清理并构建并尝试通过命令行 运行 时,我收到以下错误:
error: package com.nimbusds.jose does not exist
这是我第一次使用maven,所以我对此很陌生。
您的 pom 文件中有 maven-shade-plugin
,它创建了一个可执行文件 "fat" jar,其中合并了所有依赖项。所以在你执行 maven clean
和 package
目标之后,你应该从命令行 运行 这个 jar 像这样:
java -jar target/vertxTestProject-1.0-SNAPSHOT-fat.jar
我已经在 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 中 运行 时,一切都会编译并且 运行s。当我清理并构建并尝试通过命令行 运行 时,我收到以下错误:
error: package com.nimbusds.jose does not exist
这是我第一次使用maven,所以我对此很陌生。
您的 pom 文件中有 maven-shade-plugin
,它创建了一个可执行文件 "fat" jar,其中合并了所有依赖项。所以在你执行 maven clean
和 package
目标之后,你应该从命令行 运行 这个 jar 像这样:
java -jar target/vertxTestProject-1.0-SNAPSHOT-fat.jar