Can files outside of the Maven folder structure get compiled? - java

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.

Related

Maven: Missing Files in modules

I'm using Eclipse and I have Maven project with jar and war modules. I exported it to my github acc. and when I import it from Git it runs correctly but something is not like i wanted to. In my Parent module i have all the files, but situation changes in my jars and war module.
For example in src folder i have two folders, java and webapp, in war called "psy-webapp" java is missing. I read something about it, and i must change the path to let maven see all folders/files right? I'm also sending link to github project and a screenshot to see what i mean.
Github:https://github.com/jakubjaroszek/ltc
screenshot

Understanding of usage of Maven folder structure

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]

Intellij idea specify output folder for each source folder (like in eclipse)

I'm working with huge project which has almost hundred plugins which in turn has it's own folder. The issue is that this project was created in eclipse and for each plugin's source folder a corresponding output folder specified. I'm wondering if it is possible to do the same thing in intellij or I'm forced to use eclipse?
Just some screenshots to make thigs clearer:
In the project structure you can create an artifact for each of your library an specify an output directory.
Try File->Project Structure then in the Project Setting add new artifact and specify output directory

How to construct maven project from source code

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

where to put jar files inside repository

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).

Categories

Resources