我正在编写一个 Maven 插件,它对 Maven 项目中的依赖项进行分析。对于此分析,我需要将项目依赖项传递到文件中。基本上,我需要项目直接或间接使用的所有 JAR 作为本地文件,以便我的插件可以分析它们。
如何在现代 (~3.3.x) Maven 中做到这一点?
我在早期版本中所做的是:
注入了大量的组件和参数。
@Component
protected ArtifactResolver artifactResolver;
@Component
protected ArtifactMetadataSource artifactMetadataSource;
@Component
protected ArtifactFactory artifactFactory;
@Parameter(defaultValue="${localRepository}", required=true, readonly=true)
protected ArtifactRepository localRepository;
@Component(role=MavenProjectBuilder.class)
protected MavenProjectBuilder mavenProjectBuilder;
@Component
protected ArtifactGraphBuilder artifactGraphBuilder;
@Parameter(defaultValue="${project.remoteArtifactRepositories}", required = true, readonly = true)
protected List<ArtifactRepository> remoteArtifactRepositories;
@Parameter( defaultValue = "${project}", readonly = true)
protected MavenProject project;
Run Code Online (Sandbox Code Playgroud)
从依赖项创建工件:
final Set<Artifact> dependencyArtifacts =
MavenMetadataSource.createArtifacts(artifactFactory,
project.getDependencies(), "compile", null, project);
Run Code Online (Sandbox Code Playgroud)
使用ArtifactResolver来传递解决工件:
artifactResolver.resolveTransitively(artifacts, originatingArtifact,
managedVersions, localRepository, remoteRepositories,
artifactMetadataSource, filter, moreListeners); …Run Code Online (Sandbox Code Playgroud) 有没有办法在 CloudFormation 模板中创建某种随机或唯一值?
为什么我需要这个。在我们的模板中,我们有许多自定义命名的资源,例如AWS::AutoScaling::LaunchConfigurationwith specifiedLaunchConfigurationName或AWS::AutoScaling::AutoScalingGroupwith specified AutoScalingGroupName。
在更新堆栈时,我们经常会收到以下错误:
当自定义命名的资源需要替换时,CloudFormation 无法更新堆栈。重命名 some-stack-launch-configuration 并再次更新堆栈。
我们不想仅仅因为需要更新资源而重命名资源。
我们也不希望在我们的资源中删除自定义名称。然而,我们不介意在我们的自定义名称中有一些随机后缀。
使用“随机生成器”,解决方案可能类似于:
MyAutoScalingGroup:
Type: 'AWS::AutoScaling::AutoScalingGroup'
Properties:
AutoScalingGroupName: !Sub 'my-auto-scaling-group-${AWS::Random}'
Run Code Online (Sandbox Code Playgroud) 我有一个基于Spring 2.x的大型应用程序,包含几百个applicationContext.xml文件和几千个bean/bean工厂.
这些XML配置中的大多数都表示类似default-autowire="byName",有效地打开自动装配,但实际上只有一小部分bean是自动装配的.大多数bean属性都是显式设置的.
(这是出于历史原因,我想这就是你过去不够聪明的时候所说的.)
现在我们想要删除自动装配.我们相信只有一小部分豆子实际上是自动装配的 - 但我们不知道,究竟是什么,也不知道.我的问题是:
我们如何才能找到Spring的自动装配?
理想情况下,我们需要获取bean /属性列表,以便我们可以在XML配置中明确地注入这些内容.但是在使用调试器进入Spring内部之前,我决定询问SF上的某个人是否已经解决了类似的任务.
PS.我无意讨论自动装配是好还是坏.我们有许多内部技术原因要删除自动装配,就是这样.
我最近升级到JAXB 2.2.11并在Eclipse控制台中注意到以下消息:
10/15/14, 11:42:46 PM GMT+2: [INFO] Creating new launch configuration
10/15/14, 11:42:58 PM GMT+2: [INFO] C:\Projects\workspaces\mj2p\maven-jaxb2-plugin-project\tests\JAXB-1044
10/15/14, 11:42:58 PM GMT+2: [INFO] mvn -B -X -e clean install
10/16/14, 12:09:07 AM GMT+2: [WARN] The POM for com.sun.xml.bind:jaxb-impl:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available: 1 problem was encountered while building the effective model for com.sun.xml.bind:jaxb-impl:2.2.11
[ERROR] 'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${tools.jar} @
10/16/14, 12:09:07 AM GMT+2: [WARN] The POM for com.sun.xml.bind:jaxb-xjc:jar:2.2.11 …Run Code Online (Sandbox Code Playgroud) 我有一个Spring Boot应用程序,它有一些配置属性.我正在尝试为某些组件编写测试,并希望从test.properties文件中加载配置属性.我无法让它发挥作用.
这是我的代码:
test.properties 文件(在src/test/resources下):
vehicleSequence.propagationTreeMaxSize=10000
Run Code Online (Sandbox Code Playgroud)
配置属性类:
package com.acme.foo.vehiclesequence.config;
import javax.validation.constraints.NotNull;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = VehicleSequenceConfigurationProperties.PREFIX)
public class VehicleSequenceConfigurationProperties {
static final String PREFIX = "vehicleSequence";
@NotNull
private Integer propagationTreeMaxSize;
public Integer getPropagationTreeMaxSize() {
return propagationTreeMaxSize;
}
public void setPropagationTreeMaxSize(Integer propagationTreeMaxSize) {
this.propagationTreeMaxSize = propagationTreeMaxSize;
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试:
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = VehicleSequenceConfigurationProperties.class)
@TestPropertySource("/test.properties")
public class VehicleSequenceConfigurationPropertiesTest {
@Autowired
private VehicleSequenceConfigurationProperties vehicleSequenceConfigurationProperties;
@Test
public void checkPropagationTreeMaxSize() {
assertThat(vehicleSequenceConfigurationProperties.getPropagationTreeMaxSize()).isEqualTo(10000);
}
}
Run Code Online (Sandbox Code Playgroud)
测试失败并显示"Expecting actual not to null"表示propagationTreeMaxSize …
假设我们有两个包p1和p2类p1.M1扩展p2.M12如下:
package p1;
public class M1 {
void method1() {
System.out.println("Method 1 called");
}
}
package p2;
import p1.M1;
public class M12 extends M1 {
void method2() {
System.out.println("Method 2 called");
}
}
Run Code Online (Sandbox Code Playgroud)
让我们扩展M12与p2.B:
package p2;
public class B extends M12 {
public void doSomething() {
method1();
method2();
}
}
Run Code Online (Sandbox Code Playgroud)
这给出了一个编译错误的method1,是包保护范围内p1是不可见的p2.method2是没有问题的.
现在让我们来延长p2.M12使用p1.A:
package p1;
import p2.M12; …Run Code Online (Sandbox Code Playgroud) 我已经使用通过 Cognito 用户池连接的 OIDC 身份提供商 (SalesForce) 设置了 ALB 内置身份验证,或多或少遵循本指南。
有了这个设置我的web应用程序(Java /弹簧引导为主)接收头x-amzn-oidc-accesstoken,x-amzn-oidc-identity并 x-amzn-oidc-data用ALB转发。
我可以解析和验证这些标头中包含的 JWT 令牌,例如,从那里获取用户的电子邮件。
现在我的目标是让这个经过身份验证的用户通过 AWS JavaScript SDK 直接从客户端访问某些 AWS 资源或服务。例如,我希望用户能够列出 S3 存储桶上的对象或调用某些 lambda 函数。
我的理解是我需要为这个经过身份验证的用户生成临时凭证。但是我找不到有关如何执行此操作的特定文档。最接近的热门歌曲是:
但我无法连接那里的点。我的期望是我可能应该以某种方式使用x-amzn-oidc-accesstoken,x-amzn-oidc-identity和 x-amzn-oidc-data标头,但我没有找到任何可以做到这一点的代码。
所以我的问题是:如何为通过 Cognito 和 OIDC 身份提供者使用内置 ALB 身份验证进行身份验证的用户生成临时凭证?
在我的一项测试中,我开始遇到一个相当神秘的错误。Surefire报告如下:
-------------------------------------------------------------------------------
Test set: de.systel.streckenmatching.GeoCoordinateTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.129 sec <<< FAILURE!
de.systel.streckenmatching.GeoCoordinateTest Time elapsed: 0.128 sec <<< ERROR!
java.util.ServiceConfigurationError: sun.util.locale.provider.LocaleDataMetaInfo: Unable to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:584)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:856)
at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1078)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1301)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1386)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:89)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:86)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:86)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:124)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:346)
at java.base/java.lang.Class.newInstance(Class.java:604)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:176)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:279)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:250)
at java.base/java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:180)
at java.base/java.util.Formatter.getZero(Formatter.java:2437)
at java.base/java.util.Formatter.<init>(Formatter.java:1956)
at …Run Code Online (Sandbox Code Playgroud) 我有一个xsd架构,我正在从中生成一些java类.我正在使用jaxb代代相传.
我希望能够生成一个带注释的类@XmlRootElement,但我希望@XmlRootElement name属性与生成的类的名称不同.
在我的xsd中,我定义了以下内容:
<xs:element name="customer">
<xs:complexType>
<xs:sequence>
....
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
这段代码生成以下java类:
@XmlRootElement(name = "customer")
public class Customer {
...
}
Run Code Online (Sandbox Code Playgroud)
name的name属性@XmlRootElement与生成的Class的名称相同.我希望生成的类名是CustomerRequest.
我已经尝试使用该jaxb:class定义来更改classe名称.实际上,这个选项改变了类名但删除了@XmlRootElement注释,我需要它存在.
以下xsd:
<xs:element name="customer">
<xs:complexType>
<xs:annotation>
<xs:appinfo>
<jaxb:class name="CustomerRequest"/>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
生成这个类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "customer", propOrder = {
})
public class CustomerRequest {
}
Run Code Online (Sandbox Code Playgroud)
如何在@XmlRootElement不丢失注释的情况下使注释的属性名称与生成的类名称不同?
解决方案更新: 用户Xstian使用外部绑定提出了正确的解决方案.仅供进一步参考,我将使用内联绑定转换的解决方案更新我自己的帖子:
<xs:element name="customer">
<xs:complexType>
<xs:annotation>
<xs:documentation>Request object for the operation that checks if a …Run Code Online (Sandbox Code Playgroud) 我目前正在开发JavaScript解析器并研究ECMAScript 5.1规范.这是一个令我困惑的问题.
§ 11.2左手侧的表达式定义了以下NewExpression产品:
NewExpression :
MemberExpression
new NewExpression
Run Code Online (Sandbox Code Playgroud)
如果我正确地阅读它,那么NewExpression可能是类似的东西
new new Something
Run Code Online (Sandbox Code Playgroud)
(实际上,任何数量的news.)
这让我很困惑.怎么可能new Something再次回报你能做的任何事情new?有可能吗?
java ×4
maven ×3
jaxb ×2
spring ×2
annox ×1
autowired ×1
eclipse ×1
ecmascript-5 ×1
javascript ×1
jaxb2-basics ×1
m2e ×1
maven-plugin ×1
packages ×1
spring-test ×1
xsd ×1