代码之家  ›  专栏  ›  技术社区  ›  Emmanuel BRUNET

Java、J2EE、Javax FX、Maven:找不到基名称的捆绑包。。大黑洞?

  •  0
  • Emmanuel BRUNET  · 技术社区  · 7 年前

    “核心”对象集合(bean、Dao、j2eeweb接口)一切正常。 正在成长的应用程序我现在需要图形化和事件感知javafx应用程序方法。但是。。在处理java ResourceBundle(国际化消息和配置目的)时。。出了问题。

    我的问题是如何通过jar导入来处理这些资源管理问题?

    主要项目结构为:

    enter image description here

    任务应用程序(JAVAFX)。。不能。

    我们已经深入研究了类加载器的概念getClaas/getressourceastream等等,事实上,由于无法在应用程序模块间共享这个属性文件资源,我们对这个从python3迁移过来的体系结构感到困惑。

    核心pom文件(maven)非常简单,可以正常工作,构建也可以,并为J2EE应用程序提供所有功能(支持ResourceBundle)

    <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>org.open-si</groupId>
        <artifactId>missions-core</artifactId>
        <version>0.2</version>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <build>
    
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
    
            </plugins>
    
            <resources>
                <resource>
                    <directory>src/configuration</directory>
                    <includes>
                        <include>**/application.properties</include>
                        <include>**/database.properties</include>
                    </includes>
    
                </resource>
            </resources>
    
        </build>
    
        <dependencies>
            <dependency>
                <groupId>org.mongodb</groupId>
                <artifactId>mongodb-driver-legacy</artifactId>
                <version>3.9.1</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
            <dependency>
                <groupId>com.rabbitmq</groupId>
                <artifactId>amqp-client</artifactId>
                <version>5.5.0</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
            <dependency>
                <groupId>com.googlecode.json-simple</groupId>
                <artifactId>json-simple</artifactId>
                <version>1.1.1</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-csv -->
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-csv</artifactId>
                <version>1.6</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.0</version>
            </dependency>
    
        </dependencies>
    
    </project>
    

    J2EEWeb(任务web)pom文件如下,应用程序运行良好,可以访问“核心”资源

    <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>org.open-si</groupId>
        <artifactId>missions-web</artifactId>
        <version>0.1</version>
        <packaging>war</packaging>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <build>
            <sourceDirectory>src</sourceDirectory>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.1</version>
                    <configuration>
                        <warSourceDirectory>WebContent</warSourceDirectory>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <webResources>
                            <resource>
                                <directory>src</directory>
                                <includes>
                                    <include>**/*.properties</include>
                                </includes>
                                <targetPath>WEB-INF/classes</targetPath>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
        <dependencies>
            <!-- https://mvnrepository.com/artifact/javax.websocket/javax.websocket-api -->
            <dependency>
                <groupId>javax.websocket</groupId>
                <artifactId>javax.websocket-api</artifactId>
                <version>1.1</version>
                <scope>provided</scope>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>4.0.1</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>org.mongodb</groupId>
                <artifactId>mongodb-driver-sync</artifactId>
                <version>3.9.1</version>
            </dependency>
    
            <dependency>
                <groupId>org.open-si</groupId>
                <artifactId>missions-core</artifactId>
                <version>0.2</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/net.sf.uadetector/uadetector-core -->
            <dependency>
                <groupId>net.sf.uadetector</groupId>
                <artifactId>uadetector-core</artifactId>
                <version>0.9.22</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/net.sf.uadetector/uadetector-resources -->
            <dependency>
                <groupId>net.sf.uadetector</groupId>
                <artifactId>uadetector-resources</artifactId>
                <version>2014.10</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
            <dependency>
                <groupId>com.googlecode.json-simple</groupId>
                <artifactId>json-simple</artifactId>
                <version>1.1.1</version>
            </dependency>
    
        </dependencies>
    
    </project>
    

    gui-one(基于Javafx)找不到资源包

    <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>org.open-si</groupId>
        <artifactId>missions-app</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <build>
            <sourceDirectory>src</sourceDirectory>
            <resources>
                <resource>
                    <directory>src</directory>
                    <excludes>
                        <exclude>**/*.java</exclude>
                    </excludes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>org.open-si</groupId>
                <artifactId>missions-core</artifactId>
                <version>0.2</version>
            </dependency>
    
        </dependencies>
    </project>
    

    欢迎任何帮助。提前谢谢

    0 回复  |  直到 7 年前
        1
  •  0
  •   Emmanuel BRUNET    7 年前

    挖掘之后,我找到了一个解决方法:resources(应用程序配置resourceBundle)是在默认接口方法(>=java8)中调用的。添加一个“getConf()”方法而实现不返回所需的资源就成功了。我认为jar中的默认类加载器就是这样做的。。。不确定纯编码部分,但它是有效的^^

    public interface MyInterface {
    
        public interface MyInterface {
    
            default jobToDo(){
    
                ResourceBundle conf = ResourceBundle.getBundle("configuration.application");
                .. 
                // fails
            }
        }
    

    但解决了问题。。其实不是一个专业的问题。。。

    public interface MyInterface {
    
        ResourceBundle getConf(); // provided by the implementation class using the right class loader I think
    
        default jobToDo(){
    
            ResourceBundle conf = getConf();
            .. 
            // works fine
        }
    }
    
    推荐文章