A weird issue suddenly appeared. I cannot execute my current code. Eclipse executes older version of my code.
I have read some solutions about this, but none of them worked on my project.
I did Project > Clean and Project > Build Automatically
, change content of my project as System.out.println("hello"); and Eclipse still executes older version of my code.
This is the code that needs to be executed.
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
HTable hTable = new HTable(config, "users");
Put p = new Put(Bytes.toBytes("2"));
p.add(Bytes.toBytes("username"),
Bytes.toBytes("usr"),Bytes.toBytes("dino"));
p.add(Bytes.toBytes("password"),
Bytes.toBytes("pass"),Bytes.toBytes("123"));
hTable.put(p);
System.out.println("data inserted");
hTable.close();
}
And this is the older version of my code:
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "myLittleHBaseTable");
Put p = new Put(Bytes.toBytes("myLittleRow"));
p.add(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"),
Bytes.toBytes("Some Value"));
table.put(p);
Get g = new Get(Bytes.toBytes("myLittleRow"));
Result r = table.get(g);
byte[] value = r.getValue(Bytes.toBytes("myLittleFamily"), Bytes
.toBytes("someQualifier"));
}
I found a solution which says if there is a syntax error, eclipse runs old code. I removed all my codes, and wrote System.out.println("hello"); and it still keeps executing older version of my code.
Second solution did not help me either. I have only one workspace and I currently am using it.
If you are running your code on any server then there might be a jar or war file that is being used for deployment. But if it is a simple hello world program then try re importing your project then rebuild it.
Since I am using Play Framework, I just went to path of my project, and wrote "play eclipsify" and the current code works.
Since you're using Play Framework (as mentioned in your own answer), you should try:
activator clean, then
activator compile to rebuild.
Replace activator with play if you're not using TypeSafe Activator.
This may be a more direct approach than re-eclipsifying your project.
Related
I have a problem with one of my project. Here is a little more info about it :
Our teacher gave us a virtual machine (ubuntu) which contains Hadoop and Hbase, already setup.
The objective is pretty simple : we have a Rest api with tomcat 8.5 (RestServer project, web project), which intercept GET requests (our teacher only want us to have GET request, security reason apparently), and we need to perform, according to the url (for instance : /students/{id}/{program} will return the grades summary for this particular student (id) and year of study (program)), data selection and mapreduce job on Hbase tables. And we have a BigData project, which contains simple java code to scan and filter Hbase table. Here is the short summary of the project.
Here is the structure we use for this project : project structure
And here is what is the execution logic : we type our url in the browser, after we launched our RestServer project (right click on RestServer -> Run as -> Run on server.
Here is what we get after doing so : RestServer in the browser.
The easy part stop there. The links we see on the previous image are just for demo, they are not what we need to do in this project. The idea is to intercept the GET request from the api, in the method handling the request, get the parameters, give them to a call to the constructor of our response object, and return the object as the response (that will be transform into a JSON). The idea is to get this object (the response to our GET request) from the BigData project. So we need to make this 2 projects communicate.
Here is the code to intercept the request :
#GET
#Path("/students/{id}/{program}")
#Produces(MediaType.APPLICATION_JSON)
public Response getStudent(#PathParam("id") String ID,#PathParam("program") String program) throws IOException {
System.out.println("ID : "+ID+" program"+program);
if (ID != null) {
System.out.println("Non nul");
return Response.ok(new Response1(ID,program), MediaType.APPLICATION_JSON).build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity("Student not found: " + ID).build();
}
}
The Response1(ID,program) object is build in the BigData project. When i execute the code from the BigData project directly (as Java application), i have absolutely no problem, no error. But the idea is to use the code from the BigData project to build the Result1 object, and "give it back" to the Rest api. The problem is here, i tried absolutely everything i know and found on the internet but i can't resolve this problem. When i type my url, (which is : http://localhost:8080/RestServer/v1/StudentService/students/2005000033/L3) i get this error : error
From my research, i found that (correct me if i'm wrong) the program can't find the ByteArrayComparable class at runtime. I looked all the links i could find, and here is what i tried to resolve it :
Check if the library for Hadoop and Hbase are in both projects.
Check if the projects contains hbase-client, which is suppose to contains the ByteArrayComparable class (yes, it is in both projects).
By doing right click on RestServer -> Properties -> Java Build Path :
Source tab : i added the src folder from BigData project (and bin folder, but i can't remember where, i believe it is in one of the tab of Java Build Path).
Projects tab : i added the BigData project.
Order and Export tab : i checked the src folder (this folder is in the RestServer project, created after i added the src folder from BigData project in the Source tab).
Deployement Assembly : i added BigData project.
I copied the class which are use in the BigData project in my src folder of my RestServer project.
I saw that it can be cause by conflict between libraries, so i tried to remove some in one project and let them in the other.
I cleaned and rebuilt the projects between each changes.
I tried adding the import that seems to cause the problem by adding import org.apache.hadoop.hbase.filter.*; in the files that are involve in the execution.
I have no idea of what i can do now. Some of my friend have the same problem, even if we don't have the same code, so it seems that the problem come from the configuration. At this point, i didn't perform any mapreduce job, i'm just using Hbase java api to scan the table with some filters.
Thanks for reading me, i hope i'll find the answer. I'll keep testing and searching, and editing this post if i find something.
Here is the code for the Response1 class :
package bdma.bigdata.project.rest.core;
import java.io.IOException;
import org.apache.hadoop.hbase.filter.Filter.*;
public class Response1 {
private StudentBD student;
private Semester semesters;
public Response1(String id, String program) throws IOException {
System.out.println("Building student");
this.student = new StudentBD(id);
System.out.println("Building semester");
this.semesters = new Semester(id,program);
}
#Override
public String toString() {
return student.toString()+" "+semesters.toString();
}
public static void main(String[] args) throws IOException {
Response1 r = new Response1("2005000100", "L1");
System.out.println("AFFICHAGE TEST");
System.out.println(r);
}
}
Edit
I finally managed to resolve my problem. I put the solution here, if it can help someone in the same situation as mine in the futur.
Once you've linked your 2 projects (in the Java Build Path section of the properties of the Rest api project), you need to go, still in the properties, in the Deployment Assembly (above Java Build Path). Here you click on Add... and add all of your jar files.
I am setting up a program for a class I am taking. All the code has been provided and I have configured everything into Eclipse. I also had to use becker.jar as an external jar file in the Libraries -> Classpath. When I run the program an error occurs about a NullPointerException.
I already tried changing the becker.jar into the modulepath instead of classpath but then Eclipse cannot find the file. I also tried reinstalling becker.jar as well as redoing the entire setup for the project.
Here is the code I am trying to set up:
import becker.robots.*;
/*
Starting Template:
This file was created in order to provide you with a pre made
'starter' program
*/
public class Starting_Template extends Object {
public static void main(String[] args) {
City toronto = new City();
Robot jo = new Robot(toronto, 3, 0, Direction.EAST, 0);
new Thing(toronto, 3, 2);
jo.move();
jo.turnLeft();
}
}
When running this error shows up:
Exception in thread "main" java.lang.NullPointerException
at java.desktop/sun.font.FontDesignMetrics.getDefaultFrc(FontDesignMetrics.java:158)
at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:279)
at java.desktop/sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1183)
at java.desktop/javax.swing.JComponent.getFontMetrics(JComponent.java:1646)
at java.desktop/javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:245)
at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1680)
at java.desktop/javax.swing.JSlider.updateLabelUIs(JSlider.java:853)
at java.desktop/javax.swing.JSlider.setLabelTable(JSlider.java:824)
at becker.robots.x.<init>(SourceFile:32)
at becker.robots.RobotUIComponents.<init>(SourceFile:87)
at becker.robots.RobotUIComponents.<init>(SourceFile:110)
at becker.robots.City.a(SourceFile:228)
at becker.robots.City.<init>(SourceFile:97)
at becker.robots.City.<init>(SourceFile:47)
at Starting_Template.main(Starting_Template.java:10)
This is a bug. See for example https://issues.jboss.org/browse/PLANNER-255?_sscc=t - the becker.jar has nothing to do with it.
I am trying to run this project called "hello user". I am new to Java, so wrote a simple program that takes your name, and displays "Hello ". while Running it, I get the following error:
run:
Error: Could not find or load main class hello.world.HelloWorld
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
But when I run file HelloWorld.java, it does it fine
I am doing this on Netbeans IDE 7.2
Rather than the coding error, it could be related to IDE. Since the "Run File" runs okay, but 'Run Project" does not, I believe you have something to set up in IDE itself. Right click the project, and select "Set is as Main", now run the project. I am just giving it a guess, may not help you. But it worth a shot.If it does not help, please paste your code too.
Your class needs a public static void main(String[] args) function. And moreover I suspect that the error could be in the package.
If you want your class in <main_package>.<sub_package>, The directory structure is
- main_package
- sub_package
-HelloWorld.java
And be sure to write your class like this.
package main_package.sub_package;
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello " + args[o]);
}
}
This is all due to the naming convention in Java
You need to run the .class file containing the public static void main(String[] args) method..
Here, your HelloWorld.java file might contain a class with main() method.. So, you can run it..
This is because, execution of any Java program starts with the invocation of main().. JVM needs an entry point to your code.. Which is main().. If it doesn't find one.. It will not run..
So, make sure, whatever class file you are running, it should have main() method..
UPDATE :- And for the starting point, may be you can skip using packages.. Just go with plain Java class without packages..
This message can also appear in Eclipse (Juno 4.2.2 in my case) and I have found two potential causes for it.
In my cases:
1. a DTD was in error. I deleted the file and that solved the issue*.
2. having cleaned the project, an external Jar that I had built externally had been deleted as could be seen from Properties -> Java Build Path -> Libraries.*
*Having solved either of the above issues, it was necessary to restart Eclipse
if you are using intellij idea then just rebuilding (clean and build) project might solve your problem . because intellij might be still trying to load the old classes which are not there or changed
Make sure you call looks like below:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello user");
}
}
To run a Java class in stand alone mode, public static void main(String[] args) is the entry method, which is must.
I'm currently using the Alloy Analyzer API to build a program, and getting some peculiar behavior. Specifically, if I open a file and parse it (using CompUtil.parseEverything), then make a new Command and call TranslateAlloyToKodkod.execute_command on the parsed file and newly created command using MiniSat with UNSAT core, it runs fine. However, later in execution, my program parses a second input file (also using CompUtil.parseEverything), gets another world, makes a new command, and then I try to call TranslateAlloyToKodkod.execute_command again, it throws the following error:
ERROR: class edu.mit.csail.sdg.alloy4.ErrorFatal: The required JNI library cannot be found:
java.lang.UnsatisfiedLinkError: no minisatproverx5 in java.library.path
edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod.execute_command(TranslateAlloyToKodkod.java:390)
Does anyone have any idea why this is thrown the second time, but not the first?
To summarize, I have something similar to the following:
Module someWorld = CompUtil.parseEverything_fromFile(rep, null, "someFile.als");
//For the following, "sig" is a sig in someWorld.getAllReachableSigs();
Command command = sig.not();
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.MiniSatProverJNI;
A4Solution ans =
TranslateAlloyToKodkod.execute_command(rep, someWorld, command, options);
//No thrown error
Module someOtherWorld = CompUtil.parseEverything_fromFile(rep, null, "someOtherFile.als");
//For the following, "sig" is a sig in someOtherWorld.getAllReachableSigs();
Command commandTwo = sig.not();
A4Solution ansTwo =
TranslateAlloyToKodkod.execute_command(rep, someOtherWorld, commandTwo, options);
//Thrown error above. Why?
I tried to reproduce this behavior, but I couldn't. If I don't add MiniSat binaries to the LD_LIBRARY_PATH environment variable, I get the exception you mentioned the very first time I invoke execute_command. After configuring LD_LIBRARY_PATH, the exception doesn't happen.
To configure LD_LIBRARY_PATH:
(1) if using Eclipse, you can right-click on one of your source folders, choose Build Path -> Configure Build Path, then on the "Source" tab make sure that "Native library location" points to a folder in which MiniSat binaries reside.
(2) if running from the shell, just add the path to a folder with MiniSat binaries to LD_LIBRARY_PATH, e.g., something like export LD_LIBRARY_PATH=alloy/extra/x86-linux:$LD_LIBRARY_PATH.
Here is the exact code that I was running, and everything worked
public static void main(String[] args) throws Exception {
A4Reporter rep = new A4Reporter();
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.MiniSatProverJNI;
Module someWorld = CompUtil.parseEverything_fromFile(rep, null, "someFile.als");
Command command = someWorld.getAllCommands().get(0);
A4Solution ans = TranslateAlloyToKodkod.execute_command(rep, someWorld.getAllReachableSigs(), command, options);
System.out.println(ans);
Module someOtherWorld = CompUtil.parseEverything_fromFile(rep, null, "someOtherFile.als");
Command commandTwo = someOtherWorld.getAllCommands().get(0);
A4Solution ansTwo = TranslateAlloyToKodkod.execute_command(rep, someOtherWorld.getAllReachableSigs(), commandTwo, options);
System.out.println(ansTwo);
}
with "someFile.als" being
sig A {}
run { some A } for 4
and "someOtherFile.als"
sig A {}
run { no A } for 4
I use alloy4.2.jar as a library in my eclipse plugin project.
A4Reporter rep = new A4Reporter();
Module world = CompUtil.parseEverything_fromFile(rep, null, "civi.als");
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.SAT4J;
options.skolemDepth = 1;
When I use SAT4J, the default solver, the problem mentioned here will not show up. But another exception comes out. The reason is that my civi.als file need Integer model, which located in alloy4.2.jar under the folder /models/util/. But when I run the application, it tries to find the file util/Integer.als directly. That causes the exception. Is it possible to fix that problem?
Besides, I also tried to put the alloy4.2.jar in eclipse plugin project and run my application as an eclipse application (running my application as a plugin). With the default solver, the application has no problem at all. But when I switch to MiniSatProverJNI, the problem mentioned here comes out (I have set the alloy4.2.jar as classpath).
I'm trying to make an Eclipse launch configuration that I can launch programmatically, kind of building a custom debugger if you like.
I've already got an org.eclipse.debug.core.launchConfigurationTypes extension, as well as .core.launchDelegates, .ui.launchConfigurationTabGroups and .core.sourcePathComputers extensions.
I've got a button that executes the following code:
ILaunchManager mgr = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType lct = mgr.getLaunchConfigurationType(IOpcodeConstants.LAUNCH_CFG_TYPE);
ILaunchConfiguration[] lcs = mgr.getLaunchConfigurations(lct);
for (int i = 0; i < lcs.length; ++i) {
if (lcs[i].getName().equals("Opcode")) {
lcs[i].delete();
break;
}
}
ILaunchConfigurationWorkingCopy wc = lct.newInstance(null, "Opcode");
Set<String> modes = new HashSet<String>();
modes.add(ILaunchManager.DEBUG_MODE);
wc.setModes(modes);
wc.setPreferredLaunchDelegate(modes, "nz.net.fantail.studio.OpcodeLaunchDelegate");
ILaunchConfiguration lc = wc.doSave();
lc.launch(ILaunchManager.DEBUG_MODE, null);
My launch delegate has the following code:
#Override
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
ManagementClient client = new ManagementClient("localhost", 6961);
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
IDebugTarget target = new OpcodeDebugTarget(launch, client);
launch.addDebugTarget(target);
}
}
Everything works perfectly fine until get tries to load the ManagementClient class and throws a NoSuchClassDefException. I suspect this is because it launches in a separate environment from the actual application and as such doesn't have the .jar with the class in its classpath.
Does anyone know how to get around this issue? Cheers!
What class is it not finding, the ManagementClient or something else? Maybe in your launch configuration you need to set the target classpath yourself.
// customize the classpath
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classPathList);
Here are some other settings that may be useful:
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
projectName);
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
targetMainClass);
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
programArgs);
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, jvmArgs);
Why do you need the button that launches the configuration? If you extend the extension points you mentioned your launch configuration should appear in the debug menu of eclipse ... no need for a seperate button!?
Appart from this I would look after the dependencies of the plugin that contains "ManagementClient". The "NoSuchClassDefException" most often is a result of wrong dependency definitions (maybe the order of the dependencies is wrong [core plugins before ui plugins] ... or your class isn't in an plugin altogether?).