我正在使用這個存盤庫中的 PESTO 專案。要將這個專案用于我的目的,我必須添加 Cross-Origin-Headers,這樣我就可以通過 JavaScript 呼叫這個身份提供者。以下代碼將 Cross-Origin-Header 添加到RestIdPServer.java檔案中:
FilterHolder filterHolder = context.addFilter(
org.eclipse.jetty.servlets.CrossOriginFilter.class,
"/*",
EnumSet.of(DispatcherType.REQUEST));
filterHolder.setInitParameter("allowedOrigins", "*");
該服務器使用嵌入式 Jetty 服務器。完成后mvn initialize,mvn clean install package -DskipTests我嘗試在目標中運行工件,即所謂的PESTO-IdP-jar-with-dependencies.jar.
問題是我不能讓它包含 CrossOriginFilter 類。這是通過命令輸出的錯誤java -jar target/PESTO-IdP-jar-with-dependencies.jar 9080 0 9998 keystore.jks server1 server1:
STARTING REST IdP SERVER :9080-eu.olympus.server.PestoIdP@816f27d
2022-01-10 07:49:52.618:INFO::main: Logging initialized @159ms to org.eclipse.jetty.util.log.StdErrLog
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/servlets/CrossOriginFilter
at eu.olympus.server.rest.RESTIdPServer.start(RESTIdPServer.java:89)
at eu.olympus.server.RunPestoServer.main(RunPestoServer.java:49)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.servlets.CrossOriginFilter
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
我還嘗試了pom.xml. 這是實際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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.olympus</groupId>
<artifactId>core</artifactId>
<name>core</name>
<version>0.0.1</version>
<packaging>jar</packaging>
<licenses>
<license>
<name>Apache License Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<build>
<finalName>PESTO-IdP</finalName>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<inherited>true</inherited>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifestEntries>
<Class-Path>libs/amcl-3.2-SNAPSHOT.jar</Class-Path>
<!-- <Class-Path>libs/jetty-servlets-9.4.3.v20170317.jar</Class-Path>-->
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>eu.olympus.server.RunPestoServer</mainClass>
<!-- <mainClass>eu.olympus.server.RunPasswordJWTServer</mainClass> -->
<classpathPrefix>libs/</classpathPrefix>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Comment in to construct benchmarking jar -->
<!-- <plugin>-->
<!-- <artifactId>maven-assembly-plugin</artifactId>-->
<!-- <version>2.3</version>-->
<!-- <configuration>-->
<!-- <descriptor>src/main/assembly/assembly.xml</descriptor>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>make-assembly</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>single</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <archive>-->
<!-- <manifest>-->
<!-- <mainClass>eu.olympus.benchmark.Benchmark</mainClass>-->
<!-- </manifest>-->
<!-- </archive>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
</plugin>
<!-- PLUGIN FOR INSTALLING amcl -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>install1</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.apache.milagro</groupId>
<artifactId>amcl</artifactId>
<version>3.2</version>
<packaging>jar</packaging>
<file>${project.basedir}/libs/amcl-3.2-SNAPSHOT.jar</file>
</configuration>
</execution>
<!-- <execution>-->
<!-- <id>install2</id>-->
<!-- <phase>initialize</phase>-->
<!-- <goals>-->
<!-- <goal>install-file</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <groupId>org.eclipse.jetty</groupId>-->
<!-- <artifactId>jetty-servlets</artifactId>-->
<!-- <version>9.4.3.v20170317</version>-->
<!-- <packaging>jar</packaging>-->
<!-- <file>${project.basedir}/libs/jetty-servlets-9.4.3.v20170317.jar</file>-->
<!-- </configuration>-->
<!-- </execution>-->
</executions>
</plugin>
<!-- CHECKSTYLE -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<linkXRef>false</linkXRef>
<configLocation>google_checks.xml</configLocation>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.6</version>
</dependency>
</dependencies>
</plugin>
<!-- CODE COVERAGE -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<phase>test</phase>
<goals>
<goal>report</goal>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<!-- <limits>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>1</minimum>
</limit>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.95</minimum>
</limit>
</limits>-->
</rule>
</rules>
</configuration>
</execution>
<!-- <execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution> -->
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<!-- JUnit -->
<!-- <dependency>-->
<!-- <groupId>junit</groupId>-->
<!-- <artifactId>junit</artifactId>-->
<!-- <version>4.11</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.0</version>
</dependency>
<!-- WEBSERVICES START -->
<!-- JAX-RS -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<!-- Jetty -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.3.v20170317</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.3.v20170317</version>
<!-- <version>9.4.22.v20191022</version> -->
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<scope>system</scope>
<systemPath>${project.basedir}/libs/jetty-servlets-9.4.3.v20170317.jar</systemPath>
<version>9.4.3.v20170317</version>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
</dependency>
<!-- Http client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.9</version>
</dependency>
<!-- JWT (openID Connect) IdP -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- Bilinear pairings implementation -->
<dependency>
<groupId>org.apache.milagro</groupId>
<artifactId>amcl</artifactId>
<version>3.2-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/amcl-3.2-SNAPSHOT.jar</systemPath>
</dependency>
<!-- Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<!-- WEBSERVICES END -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.10.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>eu.olympus</groupId>-->
<!-- <artifactId>core</artifactId>-->
<!-- <version>0.0.1</version>-->
<!-- </dependency>-->
</dependencies>
</project>
此外,我將 jetty-servlets-9.4.3.v20170317.jar 添加到pom.xml檔案中提到的 libs 目錄中。
我搜索了一段時間的解決方案,但無法自己解決。我是否錯過了pom.xml缺少的類未包含在生成的工件中的某些內容,PESTO-IdP-jar-with-dependencies.jar或者我如何能夠將庫包含到 Jar 工件中?
uj5u.com熱心網友回復:
我找到了解決我的問題的方法。以下步驟解決了我的問題。
- 添加沒有依賴項,
<scope>system</scope>并且<systemPath>...</systemPath>在我的情況下,我必須添加:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.4.3.v20170317</version>
</dependency>
- 添加構建所需的整個類路徑。以下部分包括
<goal>build-classpath</goal>內部maven-dependecy-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
<goal>build-classpath</goal> <!-- new -->
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
- 在初始化階段添加這個外部庫的安裝。以下代碼為我執行此操作:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.4.3.v20170317</version>
<packaging>jar</packaging>
<file>${project.basedir}/libs/jetty-servlets-9.4.3.v20170317.jar</file>
</configuration>
</execution>
</executions>
</plugin>
這三個步驟解決了我的問題。我希望這可以幫助其他面臨類似問題的人。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/412028.html
標籤:
