I am creating a maven project from scratch, first just learn how to use maven. The main project contains no source code file, but it has two modules (app, and util). App depends on util. I would like to have a .jar from app, and have no manifest file if possible. I am able to compile the whole project with mvn clean install, but can not run the app from console.
The main project .pom is
4.0.0
com.proba
myproject
0.0.1
pom
util
app
Util .pom is
<?xml version="1.0"?>
4.0.0
com.proba
myproject
0.0.1
util
junit
junit
3.8.1
test
app pom is
<?xml version="1.0"?>
4.0.0
com.proba
myproject
0.0.1
app
UTF-8
junit
junit
3.8.1
test
com.proba
util
0.0.1
compile
org.apache.maven.plugins
maven-jar-plugin
2.4
com.proba.app.App
true
org.codehaus.mojo
exec-maven-plugin
1.1.1
site-deploy
java
com.proba.app.App
<!--<arguments> myArg1 myArg2
-->
The code doesn't do too much. App.java (that inside the app module) is package com.proba.app;
import com.proba.util.UtilClass;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
UtilClass uc = new UtilClass();
System.out.println( "QQQQQ: " + uc.print() );
}
}
I compile it with
mvn clean install
[INFO] Reactor Summary:
[INFO]
[INFO] myproject .......................................... SUCCESS [ 0.406 s]
[INFO] util ............................................... SUCCESS [ 2.074 s]
[INFO] app ................................................ SUCCESS [ 0.535 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
myproject, util, app is SUCCESS.
I try to run it with
java -jar app/target/app-0.0.1.jar
Hello World!
Exception in thread "main" java.lang.NoClassDefFoundError: com/proba/util/UtilClass
at com.proba.app.App.main(App.java:17)
Caused by: java.lang.ClassNotFoundException: com.proba.util.UtilClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
As you can see, Hello World! is printed out, but UtilClass is not found. I am able to run the build from eclipse, but not from the console. What I am doing wrong? Do you have any idea?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)