I've a simple Java project that works when I execute it at Eclipse environment. But when I try to export it to a Runnable Jar, I get the following error:
JAR export finished with warnings. See details for additional information.
Exported with compile warnings: JavaSwing/src.main.java/com/cansoft/GUIProgram.java
Exported with compile warnings: JavaSwing/src.main.java/com/util/Util.java
Jar export finished with problems. See details for additional information.
Could not find main method from given launch configuration.
I read other posts which suggest to create a MANIFEST.MF file specifying the main-class which I did. It is placed at MyProjectFolder/META-INF/MANIFEST.MF and it contains the following information:
Manifest-Version: 1.0
Class-Path: resources
main-class: com.cansoft.GUIProgram
My main class is as follows:
public class GUIProgram {
private JFrame folderCreationSubappFrame;
private Color color;
private String home;
private final static Logger LOG_MONITOR = Logger.getLogger("com.cansoft");
public static void main(String[] args) {
try {
new GUIProgram();
} catch (Exception e) {
LOG_MONITOR.log(Level.INFO,e.getMessage());
}
}
public GUIProgram() throws InterruptedException, SecurityException, IOException {
home = System.getProperty("user.home") + File.separator + "Documents";
startLogSystem();
if(isFirstRun()) {
showWelcomeFrame();
} else {
initialize();
}
} .... More and more code
Does anybody know what am I missing? Any help much appreciated.
Thank you.
It is not enough to create the manifest file, you need to explicitly choose it in the Eclipse jar export dialog.
Answer to Comment
If you use "runnable jar", make sure that you chose the correct launch configuration and that the launch configuration successfully runs when chosing "Run As" -> "Run Configurations" -> "Java Application" -> Your Configuration -> "Run"
I finally find out where the problem was, it was quite simple btw. I had created my GUIProgram within a src.main.java package, but that package was created (my bad) as resources instead of folders, so Eclipse was smart enought to run it but when trying to generate the JAR which expected a correct java project structure, it was failing because truly there were not GUIProgram java class at src path (src was not folder type but resources).
Hope I succeed explaining.
i want to know that if "MethodOrderer" class is available in JUnit5 Library FOR ECLIPSE or not, because i am unable to find it.
If not, how can i shift jupiter.api_5.3.1 to jupiter.api_5.4.2 in eclipse JUnit5 library?
Will be thankful to see your reply.
I downloaded JUnit5 jar file from "https://search.maven.org/artifact/name.remal.tools.test/junit5/1.26.97/jar" and this jar does have "MethodOrderer" class but when i add this to project dependency and run the testclass, eclipse shows up this error "No tests found with test runner 'JUnit5'."
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
#TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class JunitCalculatorV4 {
#BeforeAll
static void setUpBeforeClass() throws Exception {
System.out.println("Before All");
}
#AfterAll
static void tearDownAfterClass() throws Exception {
System.out.println("After All");
}
#Test
#Order(1)
void addTest() {
System.out.println("Add test");
}
#Test
#Order(2)
void divideTest() {
System.out.println("Divide Test");
}
}
Actually this annotation #TestMethodOrder(MethodOrderer.OrderAnnotation.class) is from jupiter.api_5.4.2 which i added as an external jar, and that might be causing conflict with the existing JUnit5 library.
My problem would be solved if the JUnit5 library is updated as a whole, or atleast the jarfile inside the library is updated.
Project > Properties: Java Build Path, tab Libraries:
You are using Eclipse 2018-12 (4.10) with JUnit 5.3.1 instead of Eclipse 2019-03 (4.11) with JUnit 5.4.0 (the screenshot shows JAR file names containing _5.3.1.v20181005- instead of _5.4.0.v20190212-).
Please upgrade.
I am using Eclipse Oxygen.3 Release (4.7.3). The following is my JUnit test class:
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
class MyMathTest {
MyMath myMath = new MyMath();
#Before
public void before() {
System.out.println("Before");
}
#After
public void after() {
System.out.println("After");
}
#Test
public void testSum_with3numbers() {
System.out.println("Test1");
int result = myMath.sum(new int[] {1,2,3});
int expected = 6;
assertEquals(expected, result);
}
#Test
public void testSum_with1numbers() {
System.out.println("Test2");
int result = myMath.sum(new int[] {3});
int expected = 3;
assertEquals(expected, result);
}
#BeforeClass
public static void beforeClass() {
System.out.println("Before class");
}
#AfterClass
public static void afterClass() {
System.out.println("After class");
}
}
When I run this Junit test, eclipse keeps popping up dialog telling "No tests found with test runner 'JUnit 5'". Why?
Your test class is currently based on JUnit 4 since it uses annotations from the org.junit package.
Thus, to get it to run as a JUnit 4 test class in Eclipse, you need to select the JUnit 4 Runner in the "Run Configuration". Click on the tiny arrow (pointing down) next to the green circle with a white arrow in it (at the top of the Eclipse IDE). There you should see your test class, and by selecting that you can switch between the JUnit 4 and JUnit 5 runners.
On the other hand, if your goal is to write a test using JUnit Jupiter (i.e., the programming model for JUnit 5), you'll need to switch from annotations in org.junit to org.junit.jupiter.api.
I had the same error, after trying everything, I have realized that the JUnit library wasn't added. So after adding it, tests worked as intended.
This happened to me because my test method was declared as private and JUnit could not detect it. After I made it public it worked as expected, of course with #Test annotation.
In Eclipse 2019-09 (4.13) is a bug that can cause the "No tests found with test runner 'JUnit 5'" error:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=551298
I added the following dependency to my project and it worked for me:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.5.2</version><!--$NO-MVN-MAN-VER$-->
<scope>test</scope>
</dependency>
the test class is not public, make it public and it should work
Take a look back to your imports.
You imports import org.junit.Test; (Used for run test cases with JUnit 4)
You need to import import org.junit.jupiter.api.Test; to run tast case with JUnit5.
You are using JUnit 4 annotations with JUnit 5 dependencies.
If you want to use JUnit 5 you should replace:
#Before with #BeforeEach
#After with #AfterEach
#BeforeClass with #BeforeAll
#AfterClass with #AfterAll
#Ignore with #Disabled
Here is more about JUnit 5 annotations https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations/
Right click the java file and choose:
Build Path -> Configure Build Path -> Java Build Path.
Choose the tab Libraries in Java Build Path, On the right side tab choose Add Library.
Select JUnit and click Next.
Choose JUnit 5 in JUnit Library version dropdown and click finish.
Now run the Test with Junit Test, it will work.
This procedure worked for me.
right click and run as -> config-> make this change and run it will works cheers!!.
My 2 cents:
Right click on project -> Configure -> Add module-info -> Give some random name.
It should automatically add there a requires in the JUnit package, if not, then manually add this:
requires org.junit.jupiter.api;
And it will magically work!
* tested on Eclipse 2018-12
My issue was that, Run works fine, debug throws this error.
I was getting this merely because of low memory in the system. Ideally, eclipse couldn't launch the debug session due to low memory in the system. Error message thrown is confusing.
Hope it helps someone!
In my current case, I encountered this error when testing the pact verification on the Service Provider side.The error was thrown because the Pact Broker doesn't have any pact to test against the Service Provider.
Visit the pact broker and ensure that there is at least one pact to test with.
I had the same problem with an Eclipse (2020-09) non-Maven project. None of the proposed solutions worked, but changing the compiler from 9.0.4 to 15.0.1 did.
I did that by selecting Preferences > Java > Installed JREsand checking the box next to jdk-15.01. You may need to install a recent JDK if none are shown.
Adding the JUnit vintage dependency fixed the issue for me.
https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4-running
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
I was using JAXB as DTO to set a stable interface between Server and Clients. Anyways this doesn't matter. What matters is I created a set of classes that result in the following compile error.
Cannot resolve XML element declaration with namespace 'namespace' and
name 'name' in this context
Eclipse underlined "name" inside quotes as an error. This class is manually created instead of xjc generated.
#XmlRootElement(name="name", namespace="namespace")
#XmlType(name="")
public class UserDTO {
private UserType userType;
#XmlElement
public UserType getDTO(){
return userType;
}
public void setDTO(UserType userType){
this.userType=userType;
}
}
where UserType is a xjc generated class
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "userType", propOrder = {
"userId",
"userName"
})
public class UserType {getter;setter}
So basically UserDTO is just a wrapper that wraps up sub jaxb types.
I'm not sure if it was platform dependent (which it shouldn't be), anyways, just to mention that this code worked perfectly on Netbeans, but when it come to Eclipse, the error prevented the compilation.
The Environment running the project was:
1. MacOsX Lion
2. JDK: 1.6.0_37
3. Eclipse Version: Juno with Package 1
4. JAXB Platform: Generic JAXB 2.1
Please anyone can share some idea?
ps: I added the JDK info and Libraries setting as Manuel suggested.
I faced this issue, you have more than one schema, at least two, both of them don't have namespace, just assign namespace to one of them.
I booted up eclipse to start on a project, and without typing in a word I already have several errors.
package department.namespace;
import android.app.Activity;
import android.os.Bundle;
public class DepartmentActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
At package department.namespace, it says:
multiple marks at this line and the type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
The import android.os cannot be resolved.
Override cannot be resolved as a type
The method OnCreate(Bundle) is undefined for the type Activity
R. cannot be resolved as a variable.
Since this JUST came up when I started Eclipse, how do I fix this?
First, you should start by cleaning and building the project. This can be done by selecting the project of interest and then selecting the appropriate option from the project menu.
If that doesn't resolve the issue, then I would recommend checking the projects build path to ensure that your expected dependencies are present and accounted for. If I remember correctly when I have had this issue in the past, it helps to remove and re-add the JRE of choice.
To look into this issue further, you might check some of the following links:
Android Dev Specific - http://kyleclegg.com/eclipse-android-error-type-cannot-be-resolved/
http://dev-answers.blogspot.com/2009/06/eclipse-build-errors-javalangobject.html
http://www.adriancourreges.com/articles/the-type-java-lang-object-cannot-be-resolved-with-eclipse/