Once we create maven project, it creates folder structure like following:
I'm planning to put my Selenium tests in src/test/java folder and resources like test data, properties etc in src/test/resources. Whatever I'm following here is correct?
If I follow above scenario, there is no use of src/main/java and src/main/resources, would be fine if I remove them from folder?
Or let me know how can I use that folder structure in better way for Selenium tests.
There is one more folder src in the project. What is that for? How can I make use of that folder?
In your project there is only one src folder, you can see it if you go to the folder directly with the browser, without using Eclipse.
What you see that structure/view is:
The source folders (Source folders are a way to cut down on a
project's indexing scope. You can mark the folders that are part of
your day to day work or part of a subsystem that you work on. All
files inside source folders will be indexed and are, thus,
searchable. Note that any files pulled in by a file inside a source
folder will also be indexed.)
Dependencies: JRE and Maven dependencies
The physical folder of src: Inside it there is the same content of the source folders, but
with folder structure, because there are same things.
Binaries and pom.xml
About the selenium case, it depends. You can create a Selenium folder in your main project into src/test/java, and put the tests there (you do not need another project) or put it another project as you said.
Basically Maven would help you to build a standard project directory structure for the type of "archetype" you have chosen. So the kind of project you created looks like a generic java project which will have a source code folder and resources folder. Corresponding to that, it would also have provision for writing unit tests during the development phase. So the folders containing "test" would hold those unit tests in form of java classes and required resources.
In your case, since you don't need the java part of the project, you could leave them empty rather than removing them. May be in future you would need to "stub" some functionality and you would use those folders.
You can explore the list of archetypes at below given link and check if any archetype exist for Simply test projects.
[http://docs.codehaus.org/display/MAVENUSER/Archetypes+List][1]
Related
I have a Java project that depends on a 3-rd party component. This component is available both as a jar and as a Maven/Ant project. One option for me is to simply add the jar as a library. However, I prefer to add the source code into my project since I may need to slightly modify their source code to better suit my needs.
What's the right way to do it in Eclipse?
My main project has a simple structure: src/ and lib/. The external component also has a standard structure: src/, test/, build/, target/, pom.xml, build.xml. So do I need to copy piece by piece (like contents of one src/ into the other src/), in which case what goes where? Or do I somehow copy it all at once? Or smth else?
The best way would be if you use maven on your projet for dependency management. This way, if you have the other projects open in eclipse, your project will resolve them as local projects, but if you don't, maven will try to fetch the jars from the configured nexus repository.
This way, you avoid having to manually configure your Eclipse projects. Maven will be able to configure your project anywhere you want to build it, not having to manually configure dependency resolution.
Import both the projects into eclipse. Add the reference of 3pp jar project to your project as a reference by clicking on Add on build path option. While delivering it as output there will be a dependency to the 3pp jar project. So either deliver it as separate jar and add it to classpath while executing your project else you have to copy the entire source files into your project and deliver it test complete jar.
Making a jar will be handled by eclipse itself.
We have a Java project that was modified about 2 years ago based on the dates.
The project uses a the Play Framework which as I recalled built and ran just fine back in 2012.
The developer apparently had tried to change the project to be a Maven project but the folder structure is all over the place and not within the Maven src folder structure.
Attempting to run the Play commands does not work on building the project any longer and using the Maven commands does not compile the code.
What occurs is just the packaging of all of the folders and source code into a .jar file.
So the question is 'Can files outside of the Maven folder structure get compiled?' if so how, OR do I need to restructure all the code to be placed into the proper Maven folder structure to try and get this to work again?
Thanks for your time.
Rough view of the folder tree below: Unable to post the POM as it is on another system
Project Name
src
main/java/
trunk
Project Name
... play framework folder structure in here eclipse, modules, precompiled, tmp
conf
lib
Web Content
META-INF
WEB-INF
Yes you can compile files in a non-standard Maven folder structure. Maven natively supports multiple source directories for the purposes of generated sources.
Read the Maven use guide When You Can't Use the Conventions
Using Multiple Source Directories This occurs when you are producing a
single JAR (or other artifact), and have several source directories
with classes you want to include.
This answer shows how to edit the directory structure in Maven by specifying the appropriate properties to override from the superpom.
The Maven pom docs show the build element set mentioned in the link above.
As a side note this answer covers a non standard directory layout for building war.
I have compiled sources of java web application. I know that project uses maven, because there is pom.xml files inside .war file.
I want to know is it possible to re create maven project using .war file. I use Java Decompiler to get sources, but i do not know how to combine all folders and .java files as it was in original project.
Is there any tool or howto to do it automaticaly?
Here is sources directory tree structure
For information: I do not want to stole some project or code, it's just my work. There is some web app in our production that was done by other developers in 2007. Now we are supporting this projects, and i don't know why customers do not have sources.
Create a new project from scratch as explained in Maven - Guide to Webapps. Then find the src/main/java directory and create a directory structure that reflects packages of classes in the war. Move the resources to resources folder. Use the command mvn package to recreate the war.
You can follow following steps. If your pom.xml is proper
Create a folder say, project
Copy your source code files with package structure intact to project folder( Note: if subfolder should src /project/src .
Copy pom.xml
In eclipse File->Import->select Maven-> Existing maven projects-> select the folder(project)-> Follow the instruction
I've seen different packages in source code such as com.website.package These packages are used across multiple applications, and I've been trying to accomplish something similar.
The only way I know of to achieve using the same packages in different projects is to copy each source file into the new project which would create the new packages. this probably isn't the preferred method, as it could possibly drag thousands of files into the project (see Java's library).
How would this be achieved?
TL;DR: How can I use a custom written package in multiple projects without copying many files? (aka Java's libraries).
Take the class files and create a jar. Put the jar on the classpath of all the applications that need those classes.
How do you do that?
Inside an IDE, you can create multiple projects and put the shared java code in one project. Make the other projects depend on that project and you can share things within the IDE. That means you run inside the IDE and it will use the shared code.
For example, in Eclipse, you choose the project that will use the shared code/project. Right click on it in the package view or navigator view and choose "properties". Select the option to set the build path and there is a tab for selecting projects that this project depends on. Select the shared project and then it's code is callable from that project.
In this case, any change you make to the shared project will be immediately available, inside the IDE, to those projects that depend on it. Run them right then and the change will be in effect.
For running outside the IDE ...
If you are using Eclipse (or some other IDE) it will have an option for creating a jar. In Eclipse you create a java project and move the classes you want to be in the library/jar into this project. Then, once you have all the right classes, including those that others depend on, you will do some sort of build to create the jar.
Eclipse has an 'export' option on the 'file' menu. Use that and select to export as a "java" > "jar" and then select the project you just made.
You can also create a Maven project of type "jar" into which you put all those classes (as java files) and then building that project with Maven will create the jar. The "install" goal for Maven will deploy it to your local repository.
Any time your shared code is shared by way of a jar, you will have to rebuild the jar and copy it into the location(s) from which it is shared by other projects before changes inside the jar take effect.
Maybe export the package to some place on the drive and create linked folders to it in the projects?
I've got a Java project hosted on github. My project needs few custom .jar files to be imported. Since I was to be able to run the project anywhere, I want to include jar files inside the git repository. Is there a recommended, conventional place where jar files should be kept, e.g. lib dir of the root project directory?
PS
At the moment I'm not using Maven and I'm not considering it.
The usual case is actually a lib folder. Or webapp/WEB-INF/lib it is a web application.
But ths usual case is bad. I would not put jars in my source management system. If you need to add references to another project, you might consider having a look a git submodules (though you are using Github).