我在Mac Yosemite上使用Maven 3.3.3和Java 8.我有一个多模块项目.
<modules>
<module>first-module</module>
<module>my-module</module>
…
</modules>
Run Code Online (Sandbox Code Playgroud)
当我构建我的一个子模块,例如,上面的"my-module",使用"mvn clean install"时,构建尝试从我在〜/ .m2中定义的远程存储库下载子模块工件. /settings.xml文件.输出低于
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-module 87.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml (788 B at 0.9 KB/sec)
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-20151104.200545-4.pom
Run Code Online (Sandbox Code Playgroud)
在尝试从远程存储库下载之前,如何强制Maven先检查我的本地〜/ .m2/repository?下面是我在〜/ .m2/settings.xml文件中定义远程存储库的地方......
<profile>
<id>releases</id>
<activation>
<property>
<name>!releases.off</name>
</property>
</activation>
<repositories>
<repository>
<id>releases</id>
<url>https://my.remoterepository.com/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>snapshots</id>
<activation>
<property>
<name>!snapshots.off</name>
</property>
</activation>
<repositories>
<repository>
<id>snapshots</id>
<url>https://my.remoterepository.com/nexus/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
Run Code Online (Sandbox Code Playgroud)
编辑: …
我用 angular 9 创建了一个 webaite,但我有 angular 的问题。
在某些路线中,我有错误:
ERROR Error: Uncaught (in promise): Error: Angular JIT compilation failed: '@angular/compiler' not loaded!
- JIT compilation is discouraged for production use-cases! Consider AOT mode instead.
- Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?
- Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping.
Error: Angular JIT compilation failed: '@angular/compiler' not loaded!
- JIT compilation is discouraged for production use-cases! Consider AOT mode instead.
- Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?
- …
Run Code Online (Sandbox Code Playgroud) 我想在特定的上下文中使用Kotlin 委托。
printMessage()
,我仍然需要以与多态继承中调用的方式相同的方式调用委托super.printMessage()
。我可以通过简单地在子句中实例化匿名委托来完成第一个任务by
(class Derived() : Base by BaseImpl(42)
使用Kotlin 的文档示例)。但是,这阻止了我访问匿名委托,因为我不知道如何引用它。
我想做类似以下的事情。然而,以下内容编译时不会出现错误'this' is not defined in this context
。
class Derived() : Base by this.b {
val b: Base = BaseImpl(42)
override fun printMessage() {
b.printMessage()
print("abc")
}
}
Run Code Online (Sandbox Code Playgroud)
我确实需要为班级的每个实例分配一个单独的委托Derived
。因此,作为全局变量移动b
对我来说不是一个选择。
我最接近我需要的是构造函数的可选参数。这也不是一个好的选择,因为我不想允许Derived
用任意的代表构建我的类。
Java 21记录模式承诺将解构引入 Java 语言。然而,它似乎与模式匹配紧密耦合,只能用作instanceof
比较的一部分或在switch
语句/表达式中。
考虑以下记录。
public record Point(int x, int y) {}
Run Code Online (Sandbox Code Playgroud)
instanceof
有没有一种方法可以在不使用or 的情况下解构该特定类型的对象switch
?以下尝试进行解构point
。但如果我们假设空安全,该代码就没有什么意义,因为instanceof
既没有也没有必要。switch
Point point = new Point(0, 0);
// destructuring with instanceof
if (point instanceof Point(int x, int y)) {
System.out.printf("Point at (%d,%d)", x, y);
}
// destructuring with switch
switch (point) {
case Point(int x, int y) -> System.out.printf("Point at (%d,%d)", x, y);
}
Run Code Online (Sandbox Code Playgroud) 我想使用 CDI 的装饰器模式来增强服务提供的业务逻辑。我尝试装饰的服务位于另一个模块(用 Maven 术语来说),因此是另一个 JAR。例如,提供的服务位于模块中com.acme.provider
,而装饰器位于com.acme.consumer
服务消费者旁边。
我的服务按原样注入,没有任何修饰。
beans.xml
装饰器在消费者模块内部声明。
我在这里提供了一个工作示例。在 上mvn install
,测试打印“Hello”而不是“Hello World”,因为它会应用装饰器。
如果我将装饰器(及其 xml 声明)移至提供者模块(请参阅decorator-in-provider
同一存储库的分支),则一切正常并打印“Hello World”。
如果装饰器仅在提供者 bean 和装饰器本身的代码位于同一模块中时才起作用,那么我认为它的用处不大。Java EE 装饰器模式有这样的限制吗?或者我做错了什么?
感谢您的见解。
java ×2
angular ×1
artifacts ×1
cdi ×1
decorator ×1
delegates ×1
delegation ×1
jakarta-ee ×1
java-21 ×1
javascript ×1
kotlin ×1
maven ×1
maven-3 ×1
repository ×1
typescript ×1