小编Ahm*_*wan的帖子

如何强制Maven使用我的本地存储库而不是去远程repos来检索工件?

我在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)

编辑: …

artifacts repository maven-3 maven

77
推荐指数
7
解决办法
14万
查看次数

未捕获(承诺):错误:Angular JIT 编译失败:'@angular/compiler' 未加载!在角 9

我用 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)

javascript typescript angular

26
推荐指数
7
解决办法
6万
查看次数

Kotlin:引用未由构造函数传递的委托

我想在特定的上下文中使用Kotlin 委托。

  • 不应在构造函数中传递委托。
  • 我想保留对委托的引用以供以后在代码中使用。例如,在我重写的方法中printMessage(),我仍然需要以与多态继承中调用的方式相同的方式调用委托super.printMessage()

我可以通过简单地在子句中实例化匿名委托来完成第一个任务byclass 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用任意的代表构建我的类。

delegates delegation kotlin kotlin-delegate

6
推荐指数
1
解决办法
946
查看次数

在java中记录模式,无需instanceof或switch

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)

java pattern-matching java-21 record-patterns

6
推荐指数
1
解决办法
910
查看次数

CDI 装饰另一个 JAR 中的服务

我想使用 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 decorator cdi jakarta-ee

2
推荐指数
1
解决办法
286
查看次数