1
votes

I have created a runnable jar file from an existing maven project on netbeans, which contains all dependencies included in pom.xml

When I run it on Netbeans it work:

stampa
adsa
stampa2

when instead I run it from the runnable jar file I get this error:

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)

I don't get it.

Why on netbeans the RepositoryException is not thrown?

The java code is the same, the build is successful and the Run is different!!!

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 server is running at

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

I have even checked it on firefox, and the repository is reachable.

I'd be glad if someone can help me to figure this out :)

1

1 Answers

0
votes

I solved it,

I changed maven plugin in pom.xml in onejar-maven-plugin and It works now.

Appearently, using maven-shade-plugin or maven-assembly-plugin, not every dependencies were added to the final jar "executable".

This pom.xml is working YEAH!!!

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