jackrabbit:当我执行可运行的 jar 文件而不是在 netbeans 上时,为什么会出现 javax.jcr.RepositoryException:无法访问存储库?

问题描述 投票:0回答:2

我已经从 netbeans 上现有的 Maven 项目创建了一个可运行的 jar 文件, 其中包含 pom.xml 中包含的所有依赖项

当我在 Netbeans 上运行它时,它可以工作:

stampa
adsa
stampa2

当我从可运行的 jar 文件运行它时,我收到此错误:

java -jar ./Prova-1.0-SNAPSHOT-jar-with-dependency.jar

stampa
adsa    

Exception in thread "main" javax.jcr.RepositoryException: Unable to access a repository with the following settings:

        org.apache.jackrabbit.repository.uri: http://localhost:8082/server

    The following RepositoryFactory classes were consulted:

        org.apache.jackrabbit.core.RepositoryFactoryImpl: declined

    Perhaps the repository you are trying to access is not available at the moment.

        at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:223)
        at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:263)
        at com.mycompany.leggitutto.Source.main(Source.java:38)

我不明白。

为什么在 netbeans 上不会抛出 RepositoryException?

java代码一样,构建成功,Run不一样!!!

public static void main(String[] args) throws Exception 
{

    System.out.println("stampa");
    System.out.println("adsa");

    Repository repository1 = JcrUtils.getRepository("http://localhost:8082/server"); 
    Session session1 = repository1.login(new SimpleCredentials("admin","admin".toCharArray()), "default");

    System.out.println("stampa2");
}

Jackrabbit 服务器运行于

"http://localhost:8082/server",

我什至在firefox上检查过它,并且存储库是可访问的。

如果有人能帮助我解决这个问题,我会很高兴:)

maven netbeans jar repository jackrabbit
2个回答
0
投票

我解决了,

我在 onejar-maven-plugin 的 pom.xml 中更改了 maven 插件,现在它可以工作了。

显然,使用 maven-shade-plugin 或 maven-assemble-plugin,并非所有依赖项都被添加到最终的 jar“可执行文件”中。

这个 pom.xml 正在工作耶!!!

<build>
    <plugins>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>

        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>

    </plugin> 

    <plugin>
        <groupId>org.dstovall</groupId>
        <artifactId>onejar-maven-plugin</artifactId>
        <version>1.4.4</version>
        <executions>
            <execution>
                <configuration>
                    <mainClass>Valid.Main.Class</mainClass>
                    <!-- Optional -->
                    <onejarVersion>0.97</onejarVersion>
                    <!-- Optional, default is false -->
                    <attachToBuild>true</attachToBuild>
                    <!-- Optional, default is "onejar" -->
                    <classifier>onejar</classifier>
                </configuration>
                <goals>
                    <goal>one-jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

    </plugins>
  </build>                      

    <pluginRepositories>
        <pluginRepository>
            <id>onejar-maven-plugin.googlecode.com</id>
            <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
        </pluginRepository>
    </pluginRepositories>  

0
投票

问题是 org.apache.jackrabbit:jackrabbit-jcr-commons 和 org.apache.jackrabbit:jackrabbit-jcr2dav 有相同的文件 META-INF/services/javax.jcr.RepositoryFactory,其中包含 Factory,正确的一个是 org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory。 下面,使用阴影插件从 jackrabbit-jcr-commons 中删除了该文件,以避免与 jackrabbit-jcr2dav 发生冲突。

 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.5.1</version>
            <executions>
              <execution>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <filters>
                    <filter>
                      <artifact>org.apache.jackrabbit:jackrabbit-jcr-commons</artifact>
                      <excludes>
                        <exclude>META-INF/services/javax.jcr.RepositoryFactory</exclude>
                      </excludes>
                    </filter>
                  </filters>
                  <finalName>turing-aem</finalName>
                  <shadedArtifactAttached>true</shadedArtifactAttached>
                  <shadedClassifierName>indexer</shadedClassifierName>
                  <transformers>
                    <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                      <mainClass>your.mainclass</mainClass>
                    </transformer>
                  </transformers>
                </configuration>
              </execution>
            </executions>
          </plugin>
© www.soinside.com 2019 - 2024. All rights reserved.