0

I'm new to Java development, here is the question: I have generated the web application
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=webapp -DarchetypeArtifactId=maven-archetype-webapp
, then i have added java.com.mycompany.app folder with the simple App.java file. By the command mvn package tomcat:deploy in my localhost:8080/manager i can see my web app, but how can I add my jar file in it?

basiljames
  • 4,777
  • 4
  • 24
  • 41
fen1ksss
  • 1,100
  • 5
  • 21
  • 44

1 Answers1

0
  • When adding a class in src/main/java, Maven compiles it and ensures it gets copied into your WEB-INF/classes directory — so no need to do anything. So your class com.mycompany.app.App should have been picked up by Maven, compiled and copied into WEB-INF/classes (you should be able to verify this in the target/ folder).
  • If you want to add another jar file into your war file, you need to add this jar as a Maven dependency in your pom.xml file.
Community
  • 1
  • 1
Sébastien Le Callonnec
  • 26,254
  • 8
  • 67
  • 80
  • I've done two of that steps, what will i do next? 'mvn package tomcat:deploy'? there is nothing in there – fen1ksss Sep 23 '12 at 15:12
  • @fen1ksss What do you mean, there is nothing in there? – Sébastien Le Callonnec Sep 23 '12 at 15:13
  • mb i'm not sure what to expect, but i want my webapp in localhost:8080/manager work like a console loading for example System.out.println( "Hello World!!!" ); from my App.java - file – fen1ksss Sep 23 '12 at 15:15
  • 1
    @fen1ksss No. If you deploy `webapp` in Tomcat, you will access your application on http://localhost:8080/webapp. `App.java` will do something only if it is a Servlet, or something else that gets executed on the server. A Java class on its own will not do anything unless called. – Sébastien Le Callonnec Sep 23 '12 at 15:17
  • so, i suppose to make a servlet to load "Hello world"? – fen1ksss Sep 23 '12 at 15:20
  • @fen1ksss The webapp should already say “Hello World”, as it creates a default JSP page; but if you want to create a class that displays “Hello World” either in the browser or on the console, yes, you’ll need a Servlet. – Sébastien Le Callonnec Sep 23 '12 at 15:23