Eclipse doesn't build my java files in web app project - java

I have an open source project (WAR file) imported to my Eclipse.
I have all java code sources in WEB-INF/src/... folder.
I have User java file with following code:
public class User {
public User () {}
public void create (){}
public void test(){}
}
Which create method has been made by the open source project creator, while test is new method that I create.
Then I tried to call from my login.jsp:
User user = new User ();
user.create();
user.test();
The user.test(); returns error The method test() is undefined for the type User, while the rest works fine.
I tried to check the build class and it only has the create method. Tried to clean and build the project, still doesn't resolve my problem. What is the cause of this error? Eclipse seems doesn't build my project.

This is quite strange since I did this before and didn't work, but now it works.
I resolve this problem by moving all the java codes from WebContent/WEB-INF/src/<my-package> to Java Resources/src/<my-package>

Related

Error: Could not find or load main class Neon Eclipse

I'm trying to execute carel programs based on CSA106a Stanford class videos available on YouTube.
I've downloaded the jar and related files, imported the whole project into Neon Eclipse and am trying to run.
While clicking "run", I get the error:
Error: Could not find or load main class (default package).CheckerboardKarel
Note: other programs that I have created in Neon from scratch are working fine (not imported ones). Please help.
I've attached the screenshots as well.
I can't tell for sure, but I think there might not be a "main" function in what you downloaded. In order for a java program to run the class you are running needs to have a main function. it should look like:
public static void main(String[] args){
...
}

Eclipse compiler error on simple Java class

I am facing a problem while i am trying to compile a code at eclipse in java. The code is the following:
public class New {
public static void main(String[] args){
System.out.println("hello world");
}
}
Parts that have errors are New, String and System. I have checked at error list and the description for error's is like:
Unable to create editor ID
The file does not exist
Any idea why this is happening?
Your project has or classes maybe has beeing dissapeared.
I can give you a possible solution
Solution: Shut down Eclipse IDE Start Eclipse IDE (with -clean to be super-safe) Reimport all projects (UPDATE: Just use File->Import->Existing Project into Workspace and browse your workspace/project directory)

Java Web Service Client (Eclipse) doesn't compile but runs

i'm trying to compile a Java Web Service client with the windows console but there are 100 errors. The client has been made in eclipse, and in it's console it works good. Here it is the code:
public static void main (String[] args)throws Exception{
try{
MireiaUPMPortTypeProxy proxy = new MireiaUPMPortTypeProxy();
proxy.setEndpoint("http://138.4.47.33:8087/axis2/services/MireiaUPM.MireiaUPMHttpSoap11Endpoint/");
String respuesta=proxy.getNER("[content]David is in the office.[/content]", "en");
System.out.println(respuesta);
}catch(Exception e3){
e3.printStackTrace();
}
}
}
When i compile the kind of errors that appear are: Cannot find symbol and org.apache axis.constants does not exist
Could you help me? i'm new at using web services and i'm so lost. The extrange thing for me is that it runs well in the eclipse console, but it doesn't compile.
it runs in Eclipse simply because dependent libs (jars!) are set in eclipse build path.
to be able to compile from OS console/terminal, you have to set classpath correctly. check eclipse build path (right click on project and look for this menu) and add those dependencies in your console command.
Please make sure your all related jar files are on class path when compiling your class files.

Small TestNG app won't run correctly

I created a Java Project in Eclipse and ran some TestNG files successfully. Now I've created a new Java Project and find out my TestNG files won't run as expected.
So, to troubleshoot, I created a very simple test2.class file shown below for my first (previous) Java Project and the same file for my new java Project (top line changed to reflect package name). When I execute this file as a TestNG app, it runs fine in my first project (prints out 'Test' in the console window). However, when I run it in the same way in my new project, nothing prints out and I don't see any errors.
I checked my Java Build Paths and they are the same for both. So, obviously I am missing something in my new java project???
package com.selftechy.seltests;
import org.testng.annotations.Test;
public class Test2 {
#Test
public void Test() {
System.out.println("Test");
}
}
Just a shot in the sky...
If this is your actual code listed, it has a compilation error because of the missing '}' in the method. So the TestNG execution does not even start.

Can't compile an application using Eclipse, Maven, and the Android Plugin for Maven

I'm trying to create an Android application in Eclipse using the Maven plugin and the m2eclipse-android-plugin as well. Things were going "ok" until recently. I'm using Helios on Ubuntu and have the latest JDK (removed the default one installed by Ubuntu).
The project references two libraries that I've also created. One is an Android specific utility project and generates the .apklib (successfully). The other library is a more general purpose set of utilities not specific to Android which produces a JAR file. Both of these projects are also built using the Maven plugin for Eclipse. In addition, I've verified that both the .apklib and .jar files are in the local repository and both included all of the generated class files as would be expected.
When it goes to build the .apk file, I'm getting a "cannot find symbol" on a class in my Android project where the symbol is a class from the non-Android utility JAR file. For some completely bizarre reason, the class file cannot be found inside the JAR file. I verified that, in fact, the JAR file is in my local maven repository and that the class file is in the JAR file. I've also run the maven install command with debugging on, copied the command line that gets fed into the Java compiler. When I execute that command in a console, I receive the SAME error (indicating that it's a Java compiler error and not a Maven error).
Has anyone else run into this type of situation before? It's extraordinarily strange and I've completely combed the command line for potential issues and, best as I can tell, everything seems correct.
Well, through what appears to be trial and error I seem to have fixed the problem. I had a file that looked "similar" to this:
import Test.TestObserver;
import com.myself.ImportedClassThatCouldntBeFound;
class Test extends ImportedClassThatCouldntBeFound {
public interface TestObserver {
public void event ();
}
public void addObserver (TestObserver observer) {
...
}
}
public class AnotherTest {
private Test test = new Test ();
public void blah () {
this.test.addObserver (new TestObserver () {
public void event () {
...
}
});
}
}
The problem happened at the TOP of the file. For some reason, Eclipse imported the inner interface!
When I "REMOVED" that import, and then changed AnotherTest to:
public class AnotherTest {
private Test test = new Test ();
public void blah () {
this.test.addObserver (new Test.TestObserver () {
public void event () {
...
}
});
}
}
it compiled correctly! I even verified it by putting the import BACK into the file and removing the fully declared interface name and it caused it to fail again! It's definitely one of the craziest compiler issues I've ever seen and once I get back the FOUR HOURS of my life that I lost researching this, I'll do more investigation into why this is occurring.
This will be the first time I do this on StackOverflow, but I'm going to mark this as the solution because it most definitely was the issue. However, it definitely requires more research (at least on my part) to try and understand what was causing the compiler to become so confused.
edited this to make it apparent that the class that had the inner interface was extending the class that could not be found when compiled
To me, it looks like a problem caused (ultimately) by putting two top-level classes into a single source code file. This is generally thought to be bad practice.
It is not clear whether the compilation error is mandated by the JLS, whether it is a bug in the Java compiler. But either way, the best fix is to not put multiple classes into one source file.

Categories