Dependency not found at maven runtime

I am new to maven and somewhat new to java. I tried Google and related sources, but I did not find what reminded me of my situation.

Now I have a maven project Xand Y. Xcan be considered as a common library with some utilities Y- it is simple JFramewith the printed "hello world"and invocation of the static method in X.

I execute the " maven install" in the project X, I get "build successful". I add the project Xas a dependency in the project Y(using the pom editor in Eclipse, browsing the repository and posting it). I execute the " maven package" in the project Y, I get "build successful". When starting a project, Yeither through java -jaror checking the bank, the project is Xabsent everywhere, and I get an unusual class exception. Eclipse finds it, and there are no compilation errors in the original editor.

Why does it only work in the Eclipse editor and not as a jar?

POM:

    <dependency>
        <groupId>com.company.deployment.shared</groupId>
        <artifactId>com.company.deployment.shared</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>
+5
source share
6 answers

Maven JAR . Eclipse, Maven / , .

, JAR .

Maven, . , , , , -jar Maven.

+7

exec-maven-plugin

mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ...
mvn exec:exec -Dexec.executable="maven" [-Dexec.workingdir="/tmp"] -Dexec.args="-X myproject:dist"

maven m2 repo , , , maven-dependency-plugin, maven-assembly-plugin

+1

, Maven , . :

java -classpath X.jar;Y.jar com.foo.bar.Main

maven jar, , . maven , Y , Y.jar.

0

Maven shade. "uber-jar", . , , JAR JAR.

0

, Y, Y, .

JAR Y, , .

, uber-jar Y:

<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2.1</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-all-in-one-jar</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
            ...
</project>

, , .. , java -jar

http://maven.apache.org/plugins/maven-assembly-plugin/ .

0

( , X.jar, Y.jar).

, appassembler-maven-plugin ( , , Y-, ) / exec-maven-plugin ( , , Y maven).

0

All Articles