I use Intellij Idea.
Java-classes use .txt files which are placed in folder where .java files are situated.
I created .jar file with maven and pom.xml. But there are no .txt in .jar file.
How to add them there?
UPDATED:
I have such structure src/main/java/Project-name/ for .java files. And src/main/resources/for .txt files. Within .java files I access files as ../../resources/filename.xml and all works fine. But .jar-files created with maven says:
Unable to open "../../resources/filename.xml"
How correctly should I declare filenames?
You are going against the convention. Java source goes to src/main/java but your resources must go to src/main/resources. The rest ist handled by Maven.
Related
I'm trying to use the #Sql annotation in my tests. It’s supposed to find the .sql files in the same package as the test, but it's not working for me with Maven. Maven isn't copying the file to the same place it's compiling the .class file. If I manually copy the file there, then it works.
How do I get maven to copy the file for me? Thanks.
Can someone please explain what's an exploded EAR ? I checked in google but couldn't find a clear answer.
Is it a different format?
What's the difference to a non exploded EAR?
A compressed EAR file, with extension .ear is just a ZIP file containing the directory structure of a JEE project. It is normally used in order to deploy a JEE project.
An exploded EAR file is just the uncompressed content of the above.
Incidentally speaking, war and jar files are also compressed in ZIP format.
The use of the wording "Exploding" instead of "decompressing" a ZIP file seems to be traditional in the java community, and is present in official documentation.
E.g.: www.java2s.com/Code/Java/File-Input-Output/classforexplodingjarzipfilesontothefilesystem.htm (on a IBM contributed source file belonging to Eclipse ).
They can be exploded with the jar command.
You can also use any compression utility, provided you keep the directory structure intact.
e.g.:
jar xvd /myapp_path/myapp.ear
I already have a war directory created through maven and i would like to use that directory instead of src/main/webapp but the target directory is not seen by GPE . Other than project refresh i do not know what wlse to try.
Change Default Output Folder path from Java Build Path-> Source
I have a mavenized project with jar packaging, have standard layout:
/src/main/java
/src/main/resources
When I execute: mvn package
I am expecting the resulting jar (non-executing) file to include the resources folder and everything inside that folder from the project(i.e. some xml files), but when I open the
jar file I only see the com folder where and the contents of the resources folder in the top level...
I think the above is default for maven3, but I want to include the resources folder in the jar file...
You will not see src/main/resources in resulted jar file.
You will only see the contents of src/main/resources in the jar file.
So, if you did not create a package structure for your resource files and dumped everything into src/main/resources directory, you will see your resource files at the top level of your jar.
If you want your resources appear under certain directory in the resulting jar file, create such a directory under src/main/resources tree.
I am using this tutorial to set up Tomcat Server. After I have put the HelloServlet.java in classes and Web.xml in the WEB-INF folder and I'm giving the command
localhost:9999/hello/sayhello
On the browser. I'm always getting ClassNotFoundException. If anyone can tell me where am I going wrong.
I'm using JDK1.6.0_30, and Tomcat7 for my sample application.
You need to put the compiled HelloServlet.class file (not the .java file) in the WEB-INF/classes folder.
Compile HelloServlet.java and place the output class file HelloServlet.class into
<TOMCAT_HOME>\webapps\hello\WEB-INF\classes\HelloServlet.class
One thing you should check is that, the HelloServlet.class should be in a package. Looks like you have a long way to go with Servlet and JSP... I recommend Head First Servlet and JSP for your reference.
In your 'WEB-INF' of 'classes' folder place the .class files and if your using JDBC, jsp's just Copy the .jar executable files into 'lib' folder. and make sure that xml file should contain the proper information.
you should follow below Web Application Directory Structure
WEB-INF/ --
web.xml --xml file
classes/ ---classes folder here we keep .class files Myservlet.class
lib/ ---lib folder here we keep all .jar files. Myapp.jar
Welcome.html
Welcome.jsp