migration an Maven projet from eclipse to a command line environment - java

I got an Maven project which is compiled in Eclipse. Now I need to migrate it to a Linux environment, and there won't be GUI interface I can use. I wonder what I should do to migrate it?
Currently , under Eclipse project folder I have the files/folders as the below:
.classpath
.project
.settings
.springBeans
doc
pom.xml
src
target
I figure all those .* folders are Eclipse meta data. so I can remove them. Then I can use the rest to form a Maven project that I can build using Maven command lines?

For a maven project to work command line, all you need is
Maven is installed and correctly exported in the $PATH variable
The pom.xml in your workspace.
Just go to the project directory and run mvn install.

mvn clean
then remove .project .classpath
if you want to lose eclipse project settings while migrating delete .settings (assuming it doesn't have machine specific path/settings)
copy rest to new linux environment
open eclipse, import project as maven project (assuming you have new eclipse with maven plugin setup on linux environment)
Note:
make sure you still have a backup before you successfully migrate over
.classpath contains references to local .m2 when used with eclipse and maven so the path would differ in linux and would create issue
.project contains some configuration that is eclipse maven plugin dependent, so it is good to loose it once and let new environment create new one

Related

Running a project built in docker in Eclipse

Sorry if I am being ignorant but I am quite confused on
How to run this project in eclipse:
https://github.com/ivanlomba/taboleiro
It was packed with docker and I have no experience with it whatsoever.
If anyone could help me out it would be great!
I'm not an Eclipse user, but It's a Spring Boot application and uses Maven as build tool, so you can import the project (files inside code folder) as "Existing maven project". There are tons of tutorials about creating/importing a Spring Boot project with Eclipse and Maven if you have any doubts.
If you don't use Docker you will need to configure the mysql database manually. You can find the schema of the database inside resources folder.
Docker part is only to deploy. Search for how to set up environment variables in your OS.
get Java 8 or newer, make sure the folder above bin of Java is defined as JAVA_HOME (like if your javac.exe path is "c:\program files\java\java8_121\bin\javac.exe" then JAVA_HOME="c:\program files\java\java8_121" without slash in the end
Download maven, unzip to a folder like c:\apps\maven then add the parent of the bin folder as MAVEN_HOME
like MAVEN_HOME=c:\apps\maven\maven_4_xyz
Change the PATH variable to be
PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%PATH%
Now in termimal cd to the code folder of where you have cloned or unzipped https://github.com/ivanlomba/taboleiro/tree/master/code then give the commands
mvn install
mvn test
Now in IDE install maven plugin too if its not there, then can import as an existing maven project.
If your in linux change the paths to
MAVEN_HOME=/path/maven_4_xyz
and
export PATH=$JAVA_HOME/bin:$GRADLE_HOME/bin:$MVN_HOME/bin:$PATH
in ~/.profile or other place

Why Eclipse m2e plugin deploy wrong formatted jars to Tomcat server

I am using Eclipse m2e plugin to import existing web app to Eclipse. And Tomcat is used to deploy the web app. I run the Tomcat from Eclipse' Servers list.
And everything works fine except when I got ClassNotFoundException when I tried to Run the project on Tomcat Server. The not found class is a class from another m2e project which is depended by the web app project.
And I navigated into the web app deployment folder like
$EclipseWorkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/MyApp/WEB-INF/lib
and found out the jar containing complained not found class was indeed generated in WEB-INF/lib. But the jar was in weird layout.
The layout was like below
src/main/java/com/mycompany/xxx.java
target/classes/com/mycompany/xxx.class
but not expected
com/mycompany/xxx.class
I looked into the Deployment Assembly section of the web app properties, everything was fine.
Why the Eclipse(or the m2e plugin) generates wrong formatted JAR files?
I was using maven Eclipse plugin to generate .classpath, .project files and .settings/ folder for Eclipse, via
mvn eclipse:eclipse
.
I didn't clean all these Eclipse
.classpath file
.project file
.wtpmodules file
.setting folder
before I used Eclipse m2e plugin.
At the end I deleted all these
.classpath file
.project file
.wtpmodules file
.setting folder
.
And re-import all the maven projects to Eclipse using m2e plugin.
Then the issue I mentioned was gone! All jars are now in good shape!
Looks like the existing Eclipse files causes the m2e plugin not happy, and generated unexpected result.

Why can I not add .jar to eclipse git repo?

I am using Eclipse Kepler for Java. Normally you can add internal/external .jars to a Java project in the build path located in the properties. Why, when I clone a git repo and import it into my projects, do I lose that ability? I don't understand. I kinda need to do that.
This is probably because the .gitignore has been configured to ignore .jar
Open the .gitignore file and remove the line *.jar, you should be able to add it.
======
As an aside - usually, for Java projects .jar files are not committed to repository (as they are large & it can slow down repository cloning), instead maven or gradle is used to configure dependencies. Example - http://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/
Then when you want to work with eclipse just run mvn eclipse:eclipse to generate the necessary files. .gitgnore is usually set up to ignore *.class, *.jar, .project, .settings, .classpath
I found that if you open the run configurations and go to the Classpath tab that you can add internal/external .jars. The run configuration can be accessed by clicking Run > Run configurations. I added my .jar to the user entries. The bootstrap entry caused a null pointer.
When a project relies on libraries/modules, it's best to use a build tool for dependency management. JVM ecosystem is dominated with three build tools: Gradle, Maven and Ant.
How it works:
In a build script we declare dependencies of the project. This tells the build tool where to retrieve libraries/modules our project depends on. Dependencies are resolved at runtime; downloaded from a remote repository, retrieved from a local directory or if required another project to be built in a multi-project setting.

Excluding svn directory when deploying to Tomcat in Eclipse

I have a Java project which is separated into 23 sub-projects that are all checked into a subversion repository. When they are checked out (not using the Eclipse SVN tool) there's a .svn directory on several levels of each sub-project. Then I run mvn eclipse:clean eclipse:eclipse on the whole thing (as these are Maven projects) I can import them into Eclipse and work there. So far, so good.
Here's the problem: When I deploy the project to Tomcat in Eclipse (oh yes, it's a web project) the .svn directories are also deployed. I can circumvent this by adding Resource filters in Eclipse (project properties -> Resource -> Resource Filters -> Add -> Exclude all, Files and folders, All children (recursive), Project Relative Path matches **/.svn) but every time I recreate the projects with maven (which I have to do ever so often) I have to recreate the filters for each of the 23 projects. Is there a better method to exclude resources for the tomcat deployment?
Note: I'm using
Java 1.6,
Eclipse Juno,
Tortoise SVN 1.7.6 (which comes with Subversion 1.7.4),
Maven 3.0.3 and
Tomcat 7.0.35
I am, sadly, not allowed to update anything. An ideal solution for me would be something like a global resource filter in Eclipse or some setting which would make Maven create Eclipse projects with such resource filters already set.
if you have the option to change the pom.xml, then I would expect that you can use sourceExcludes. That would be the automated version of your manual handlings.
There's also an example with svn files:
http://maven.apache.org/plugins/maven-eclipse-plugin/examples/specifying-source-path-inclusions-and-exclusions.html
Just use latest svn client - it will create only one .svn folder at parent folder.
Also, latest eclipse can import maven project without mvn eclipse:eclipse.

m2e maven eclipse plugin not configure the build path

I import a project to my workspace and convert it to Maven project using m2e and ran the pom file with goal specify "clean install".
But my project build path is not populating with the jars already downloaded to my local repository which still gives compilation errors in the source.
When i expand "Maven Dependency" variable in the library tab of build path, i can not see the jars already downloaded?
Was there existing Eclipse metadata when you imported the project, perhaps from another developer? This is a frequent cause of failure in Eclipse, especially if you have metadata from the earlier m2eclipse plugin.
I have encountered the situation many times (in Juno and Kepler) where the .classpath is incorrect, resulting in the symptom you describe, and I either have to rewrite the .classpath myself or nuke it and encourage Eclipse to try again.
In your case:
delete the project from your Eclipse workspace (but not the filesystem)
delete the subdirectories .settings and target, and the files .classpath and .project from the project directory
re-import the project into Eclipse via File -> Import... -> Existing Maven Project
The Eclipse dot-directories will be created from scratch, and the project should already be configured as a Maven project; artifact retrieval should start in the background.
If this fails, check the 'Maven Console' in Eclipse for clues, and/or the Eclipse Error Log.
As other people have commented, you need to ensure that your m2 settings file is being correctly interpreted by m2e.
Can you build successfully from the command line?

Categories

Resources