I am working with a very old codebase where no build/library management tool such as maven or ant is used. All library is copied in the local lib directory. I found the stand-alone Junit. That I can import the library in my project. I downloaded and put it in the lib and also configure the build path in the eclipse. I can't import Mokito library in my unit test code. I don't know how do I setup mokito as a standalone library in my project. As shown in the picture below. Please let me know how can I setup this:-
Maybe an easier way to gather all depencies is to configure a maven project somewhere else (using eclipse), then export it as runnable jar. Check the option to export all dependencies into a folder.
You will have to change the scopes, because some scopes are ignored (like test).
Then copy the folder to your old project and import all of the jars into the classpath. You still need to check for conflicts manually.
Or you just mavenize the old codebase instead ;)
Related
I am trying to use loaded jar files of my class path into my module. I
know requires will accept only modules names.
my jar files are present inside the Spring Jar Files folder.
I tried to use #Configuration annotation inside my appConfig.java file and IDE could not recognize it.
Your help is much appreciated as I am new to the programming world.
Normally, I use Maven or Gradle to handle all the jars.
It seems you have just started with Spring.
I suggest you try Spring Boot with Maven or Gradle to manage the library and the code lifecycle (compile, build, test).
This is one tutorial for example: https://spring.io/guides/gs/spring-boot/
You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar.
Example link
The above solution is obviously a "Quick" one. However, if you are working on a project where you need to commit files to the source control repository, I would recommend adding Jar files to a dedicated library folder within your source control repository and referencing few or all of them as mentioned above.
I'd suggest go for the second one if you are planning to build this as a proper project and put it in a source control repo.
I'm trying to replicate in Intellij something easily done in Eclipse.
I want to run this Main class from the mainProject (nevermind the errors due to the use of fictional names):
Now, the problem is I need to be able to import a configuration folder from another project, in order to run the Main class. This is easy in Eclipse:
But I don't know how to do this is Intellij. Ideas?
This is actually why I despise the Eclipse workspace. It lets developers cheat and use another project's source as a dependency of another project. This is a problem because this isn't how it works outside of the IDE.
What you need to do is create a jar of classes you depend on, then include that jar as a dependency of the project that depends on them. If you use dependency management and have a local repository (like nexus or artifactory) you can publish your jar to your local repository and then in your other project just include it in your pom.xml if you are using Maven or build.gradle if you are using Gradle.
If you are instead including libraries in your source folder, copy the jar to your project, then right click on the jar in IntelliJ and select "Add as Library...". You can also add a dependency through File->Project Structure->Modules->Dependencies tab. Add as Library is a shortcut to adding a library here and the dependency shows up here if you use Add as Library.
IntelliJ does let you import a module from another project, but again this is cheating because it will just confuse you down the road because it will only work from within the IDE, not running as a standalone application. (File->Project Structure->Modules->Plus (+) Sign->Import Module)
I am making a small java library to parse URI parameters. I implemented it, and am in the process of making JUnit tests for it. I realized that I needed to use a mocking framework, and I did some research and chose Mockito. But since I am not using Maven or Gradle, I do not know how to include the Mockito jar files in my Eclipse project. Reading the documentation, I found that I need to use the Mockito-all jar file, instead of the Mockito-core jar file, but the Mockito-all release has been discontinued since v2.
I looked at Mockito-core's pom file, and found that it depended on other libraries. Is the only way for me to be able to use Mockito to track down all the dependencies of Mockito-core, and dependencies of those dependencies, and to download all those jar files? Or is there a simple way for me to get a single jar file for the latest version of Mockito?
Edit
I know:
how to import jar files into eclipse
how to add user libraries into a project
I don't know:
which mockito jar(s) to download
where to get those jar(s) from
download mockito jar(s)
in eclipse
create a user library
add the user library to your projects classpath
What jar(s)? I know how to add them in eclipse, but I don't know where to download the jars from. I will clarify in the question – vikarjramun
http://repo1.maven.org/maven2/org/mockito/mockito-core/2.7.22/
http://search.maven.org/#search%7Cga%7C1%7Cbyte-buddy
http://search.maven.org/#search|ga|1|byte-buddy-agent
http://search.maven.org/#search|ga|1|objenesis
I am new to Java and trying to import an API from GitHub, to use its functions in my project. API is on GitHub as Java files, but the only documentation I can find on the web is for Jar files.
I just need to access these functions in my code in Eclipse---what do I do?
Thanks!
Your various options include:
Figure out if the jars exist in a maven repository. Typically the project will mention that in their documentation. If so, you can use a package manager like maven or gradle to download that jar into your project.
If the project does not have jars in a public repository, check the Releases tab in github. It may have jars that the project owners have built.
If those are also not there, clone the repo and build the code into a jar yourself. The project would likely have build scripts committed or otherwise docs for how to build it.
I am updating an existing project from GWT 1.5.2 to GWT 2.0.0. We use maven 2 to manage our dependencies and do all of our development in Eclipse 3.5.
Because we use maven to manage our dependencies, I do not have all of those jars in the war\web-inf\lib directory as GWT specifies. Instead, they are in the maven repository, just where maven likes them. I have the project set up so that maven can successfully build and launch in either dev or web mode and the application runs correctly.
The problem is that when I launch from Eclipse, I get a java.lang.NoClassDefFoundError. If I manually copy of my dependencies into war\web-inf\lib before launching, everything runs fine, but that doesn't lend itself to a long-term solution. First, if I check all of those jars into our version control, that will subvert much of the value we get from maven. As annoying as maven can be, ditching it is not the answer. Second, having developers manually copy them over every time they want to debug something is ridiculous.
So can I get Eclipse to copy the dependencies into war\web-inf\lib before launching? Is there an alternate solution that I'm missing?
Thanks,
Tony
Running the gwt:eclipse goal will copy the maven dependencies into war/WEB-INF/lib. See the Eclipse Configuration section of the Eclipse IDE Integration documentation of the Maven GWT plugin for more details. Also have a look at this answer about Maven GWT 2.0 and Eclipse.
You should install the m2eclipse plugin and use that to build your project within eclipse. This will invoke maven as an external tool from within eclipse.
Your maven project artifact type should be set to war, which will let maven discover the dependencies and bundle them.
See these links:
force Maven2 to copy dependencies into target/lib
http://maven.apache.org/plugins/maven-war-plugin/
http://maven.apache.org/plugins/maven-war-plugin/examples/rapid-testing-jetty6-plugin.html
a maven aware IDE (idea, eclipse, netbeans) should do this packaging automatically. maybe you:
forgot to enable maven import inside IDE?
did not add these dependencies to the pom.xml (so they aren't included in the 'mvn package' phase)
added wrong scope to dependency declaration (e.g. scope 'provided' or 'tested'), so they are ignored for runtime
If you have the packaging method in your pom.xml set to war it should copy runtime depdencies into target/war/WEB-INF/lib.
Or is your project to build something larger like an ear? If so you should probably split your pom.xml into multi-project format.
As for Eclipse, I'm not terribly familiar with it so I can't really help you there. Are you (or can you) run a maven target (like "install") when you do a run or debug?
This is not supposed to be a problem. If you are using Eclipse+WTP then WTP lets you declare jars listed under 'J2EE module dependency' in the project's properties. Those jars are automatically published to tomcat (see note at the end of this comment)
You need to declare an M2_REPO variable in your eclipse environment (search eclipse help for 'classpath variables'), it should point to your local maven repository, and just add external jars from there to your project and mark them as 'J2EE dependencies'.
I did that with tons of projects, Maven and Eclipse live side-by-side :) (without m2eclipse)
A second option is to try to integrate Eclipse and Maven with m2eclipse plugin, as crowne mentioned, but I found this unnecessary.
There is a third option, if you don't use WTP (but you should). Assuming that you use tomcat, then you can copy those jars to $(tomcat.home)/common/lib. If you can do it just for your private instance of tomcat (on each developer's machine) then you are good to go.
This is supposed to be a low-impact solution that will get those jars into the classpath at runtime, but it doesn't scale well.
note: unfortunately the classpath of Eclipse web projects can be confusing. When you add jars to the regular build path of the project, they are not deployed (copied over) to tomcat. To solve this, WTP defines a special library called Webapp Library - this library contains all the jars in the project's WEB-INF/lib folder, as well as all the external jars that are marked as J2EE Module Dependencies. All those jars find their way appropriately to WEB-INF/lib when published to tomcat.
Quite simple:
1. Create a "lib" folder under your project like this:
"\src\main\webapp\WEB-INF\lib"
2. Copy needed "jars" etc that you want included inside your WAR bundle folder.
3. Invoke your maven build as you normally do. I use "mvn install", which creates builds the war file.
If you examine the WAR file, your jars that you included in step-1 and step-2 will be there.
Cheers.