I want to create /java, /resources, and /webapp/WEB-INF/web.xml folder structure under src.
I have used the -DarchetypeArtifactId=maven-archetype-webapp but it creates /resources /webapp/WEB-INF/web.xml but doesn't create /java folder.
So in spite of creating the folder /java in eclipse manually is there any other way to create with some -DarchetypeArtifactId= so that it creates the above folder structure.
I'll be thankful if someone can tell me how can I customize and design my folder structure and create it with maven without using existing template.
When you use -DarchetypeArtifactId=maven-archetype-webapp, java folder wont be created. It needs to be created manually.
It created the following structure
src
└── main
└── resources
└── webapp
└── WEB-INF
Best choice is to follow Maven standard directory layout:
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
Archetypes are minimized due different programming languages can be used for web development:
http://cvs.peopleware.be/training/maven/maven2/standardDirLayout.html (link goes to web.archive since the main link is dead)
It will minimize configuration of plugins and also will simplify understanding and maintenance of Maven projects
you can create a Maven Webapp using following archetype
-DarchetypeArtifactId=maven-archetype-webapp
which will automatically creates the desired folder structure
in your case its apart from src\main\java
src\main\resources
src\main\webapp
Related
I'm having difficulty understanding how to structure a go project using packages, especially when this project it nested within a repository.
I would like to have the following folder structure within a repository for my go application.
github.com/user/repo
└── client
└── server
└── <create go application "package main" code here>
└── package1
└── <create package 1 code here>
I want to create my go application/module within the server directory within the repository. However I'm not sure what is the correct or 'best practice' to do so.
I'm not sure if the go.mod file should be created within the root directory of the repository or the sub directory server?
Should the module name within my go.mod file be github.com/user/repo or github.com/user/repo/server?
If I have a package called package1 within a sub directory called package1 of the server folder, what would the import path be to import it?
The general best practice is to put your go.mod file at the root of the repo, and have only one module per repo. Then all of the packages within the repo will be in the same module and share the same dependencies.
It is possible to define multiple modules within a single repository, but doing so adds a lot of maintenance overhead: if you have multiple modules, they are treated as completely separate; you have to explicitly manage the dependencies between them, and you have to explicitly tag separate releases for them.
For most projects, that extra overhead comes with very little benefit: mainly it allows you to tag stable releases for the different modules at different times. In my experience, for most projects that extra flexibility is not worth the maintenance cost.
While building using gradle, the protos are generated inside my build folder and generateProto task looks for protos in src folder. Hence generateProto cannot find the protos to generate classes.
Error :
:generateProto
file or directory '*****/src/main/proto', not found
Thanks in advance,
I'm working on a project which uses JAAS and unfortunately for me Tomcat requires a file to be put in a META-INF folder in the root of the war
app.war
|__META-INF
| |___context.xml
...
I think that it's already weird since the default META-INF location for WAR's is in the classes folders.
app.war
|__WEB-INF
| |__classes
| |__META-INF
...
So I'm using Maven, which states that anything in src/main/resources/META-INF will be copied to the appropriate place, which it does. The weird thing is that it is also creating a META-INF folder in the root of the file structure leaving me with 2 META-INF folders.
Project Structure
app
|__src/main/java
|__src/main/resources
| |__META-INF
| |__context.xml
...
After mvn package
app
|__META-INF [1]
|__WEB-INF
| |__classes
| |__META-INF [2]
| |__context.xml
...
So, if the war standard states that META-INF should be under classes folder, as in #2, why maven war creates the #1 folder. And is there a way to make it copy files into that folder instead of #2?
Regards
So I found this:
Two Meta-Inf folders - normal structure?
which states that having 2 META-INF folders is not a problem. Digging a little I found:
JAR File Specification
which states about the META-INF folder:
A JAR file is essentially a zip file that contains an optional META-INF directory. ...The META-INF directory, if it exists, is used to store package and extension configuration data, including security, versioning, extension and services.
and this:
JSR-000315 JavaTM Servlet 3.0
which, on section 10.6, states about the WAR file structure:
When packaged into such a form, a META-INF directory will be present which
contains information useful to Java archive tools. This directory must not be directly
served as content by the container in response to a Web client’s request, though its
contents are visible to servlet code via the getResource and getResourceAsStream
calls on the ServletContext. Also, any requests to access the resources in META-INF
directory must be returned with a SC_NOT_FOUND(404) response.
So from the WAR spec the right place is WEB-INF/classes/META-INF. Yet, since war is a special jar file, it makes sense to have /META-INF as a point for extensions. One can see such different uses in JPA persistence.xml vs. Tomcat context.xml files: the former should be placed in WEB-INF/classes/META-INF while the latter in /META-INF.
I have a maven project that is generating a .war file.
I want to configure maven to generate an executable jar, that embeds a servlet container (jetty, tomcat, or others) plus my war application, and generate an executable jar that can run my web application with a command like:
java -jar mywebapp.war
Is there a maven plugin to obtain such artifact?
At the moment I'm using jetty-runner to run a test version of my app, it's quite satisfying for test, but not as as handy for redistribution as it would be an executable war (like in jenkins).
Update
#jesse-mcconnell: I don't want to change a single line in my web application (except in the pom.xml) to achieve the result. It's just a matter to package my war differently, and keep it deployable under an appserver of choice, plus having the ability to run it as an executable war.
A perfect solution should also give me the ability to choose which appserver to embed, also specifying all needed configuration files contained in the executable war itself.
#khmarbaise: I know about jenkins, I already checked the code long time back, it uses winstone servlet container, and it puts a Main.class in the war which is accessible from http (and I think it's wrong)
A perfect solution could generate a war containing stuff like this:
├── META-INF
│ └── MANIFEST.MF (Main-Class: WEB-INF.container.classes.Main)
└── WEB-INF
├── web.xml
├── classes
├── lib
└── container
├── lib (jetty.jar/tomcat.jar/whatever.jar)
├── etc (configuration files for the container)
└── classes
└── Main.class
Main.class should use etc configuration as default, but being able to override common parameters at the command line (port, context,etc) or specifying a new configuration.
Main.class should be able to load the container jar and configuration from inside the container (or extract into tmp.dir) and start up the appserver.
This is how I would make it.
At the end, you have a normal war, that can be deployed in any appserver, with the ability to run in a self-contained way.
Tomcat Maven plugin do that have a look here http://tomcat.apache.org/maven-plugin-2.0/executable-war-jar.html
HTH
Use the maven jar plugin to set the Main-Class in the manifest, and then write a main method with something akin to this (or that calls into code like this):
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContext.java?h=jetty-8
You can register your servlets and wire up the webapp accordingly.
The issue with bundling a war file proper inside of a jar file is that you would need a specialized deployer that understands deploying a war file from within a jar, not a common thing. So creating an uber type jar is probably the better way to go. Besides, one of the big reasons of the actual WebAppContext is the classloader isolation which is kinda moot in these cases.
You can use the maven-dependency-plugin to unpack the various dependencies you need. There are other plugins you can use like the maven-uberjar-plugin (I think that was the name) but you can do it simply with the maven-dependency-plugin + a custom main class akin to something like the above.
I like this approach as you end up with a main method that you can run in eclipse that starts up the whole application and lets you debug the whole thing as well, often quite a win.
Edit: for posterity, jetty also releases with an artifact called jetty-runner that allows for running war files directly off of the command line
No that i know but check the jenkins source code which supports starting directly from command like you expected to work.
How can I add META-INF/context.xml into the war? I didn't find any config entry in config/warble.rb.
Unfortunately Nick's method doesn't work. The file is actually copied to WEB-INF/META-INF/context.xml.
I finally figure out a way to copy context.xml to META-INF:
create META-INF/context.xml under your rails app root folder
uncomment and change the following line in config/warble.rb
config.public_html = FileList["public/**/*", "doc/**/*", "META-INF/context.xml" ]
Basically treat META-INF as public_html, and it will be copied to webapps/youapp/META-INF.
You'll have to add one yourself. You can either create a META-INF/context.xml directory and file in your project and add META-INF to config.dirs in config/warble.rb or you can add a "pathmap" to rename the context.xml file into the META-INF directory in the war file.
config.pathmaps.application += ["%{context.xml,META-INF/context.xml}p"]
A better way of tackling this might be to use the following in your warble.rb file.
config.script_files << 'path_to_file/context.xml'
See documentation towards bottom of https://github.com/jruby/warbler/blob/master/lib/warbler/config.rb
# These file will be placed in the META-INF directory of the jar or war that warbler
# produces. They are primarily used as launchers by the runnable feature.
attr_accessor :script_files