maven RepositoryException:Unable to access a repository when I execute a runnable jar file and not on netbeans?

5jdjgkvh  于 2023-11-17  发布在  Maven
关注(0)|答案(2)|浏览(133)

我已经从netbeans上现有的maven项目中创建了一个可运行的jar文件,它包含pom.xml中包含的所有依赖项
当我在Netbeans上运行它时,它可以工作:

stampa
adsa
stampa2

字符串
当我从可运行的jar文件中运行它时,我得到了这个错误:
java -jar ./Prova-1.0-SNAPSHOT-jar-with-dependencies.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代码是一样的,构建成功,运行是不同的!

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服务器运行在
第一个月
我甚至在firefox上检查过,仓库是可以访问的。
如果有人能帮我解决这个问题,我会很高兴:)

xzlaal3s

xzlaal3s1#

问题是org.apache.jackrabbit:jackrabbit-jcr-commonsorg.apache.jackrabbit:jackrabbit-jcr2dav有相同的文件META-INF/services/javax.jcr.RepositoryFactory,其中包含工厂,正确的是org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory
下面,这个文件是使用shade插件从jackrabbit-jcr-commons中删除的,以避免与jackrabbit-jcr 2dav冲突。

<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>

字符串

wljmcqd8

wljmcqd82#

我解决了,
我在onejar-maven-plugin中更改了pom.xml中的maven插件,它现在可以工作了。
显然,使用maven-shade-plugin或maven-assembly-plugin,并不是每个依赖项都被添加到最终的jar“可执行文件”中。
This pom.xml is working耶!!

<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>

字符串

相关问题