I created an Aspectj project and added .aj files and java files. While compiling(Load-time) it shows the error
"Error: Could not find or load main class javaagent:path/aspectjweaver-1.8.2.jar"
I compiled it in eclipse by creating Load time configuration file.
Can any one tell me why
Very simple: Probably you should provide a real file system path instead of the place holder path. Also be sure to use -javaagent:... (note the dash character) instead of something like javaagent:....
Related
My code has gotten quite large and so I've decided to build a runnable JAR to see how it's done. I probably should've tried sooner because I'm getting 2 different errors related to the project structure, first is the "no main manifest attribute error" when trying to run the JAR from command prompt. Double-clicking the JAR does nothing (Win7). The second issue is related to the FXMLLoader explained lower down.
I followed the steps here to build the JAR, which involved moving all Maven files into the JAR directory. The compiled JAR gave me the manifest error, so I followed this which adds a Maven plugin in my pom.xml file. The error might be caused by a wrong naming convention with the line <mainClass>com.primary.Drag</mainClass> where primary is the package and Drag is my Drag.java file (class) which has the main method.
Inititally I was using the default package but read that this is not recommended for larger projects, so I put all my files into "primary". Here is my current hierarchy as shown in IntelliJ:
The problem is that ever since I created the "primary" package, I can no longer even compile the program via IntelliJ, let alone build a runnable JAR. This is due by the second error I mentioned, which is java.lang.IllegalStateException: Location is not set. on this line within primary/Drag.java:
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("firstlaunch.fxml")); It used to work with the default package, but not anymore.
I tried replacing firstlaunch.fxml with /primary/firstlaunch.fxml and /resources/firstlaunch.fxml (with and without moving resources into primary package) but no luck.
3 Related Questions:
Is my project structure incorrect?
How do I reference the fxml file from the primary package?
Is this what I should write in Maven's mainClass tags? <mainClass>com.primary.Drag</mainClass>
Is my project structure incorrect?
Answer:
Your package name should be like com.primary.******
How do I reference the fxml file from theprimary package?
Answer:
Always make sure that you are trying to load firstlaunch .xml from the class which is located in same package where that xml is kept. Means class which you wrote the loading code and xml file should be in same package
Is this what I should write in Maven's mainClass tags?com.primary.Drag
Answer:
If you package name corrected to com.primary , your main class Drag will correctly added by maven
My top level debug class as specified in the debug configuration is MyDebugClass. Further down in the main, it attempts to launch an instance of class ProblemClass that is in the same package as MyDebugClass but it errors out on the constructor invocation line saying "Source not found". The project compiles fine and the .class file is indeed in the target directory, the same place as the .class for MyDebugClass.
I thought there may have been something odd with the classpath so that the same package where the debug main is not included so I made a test class in the same directory and tried to invoke an instance of it and that worked. So that is not the problem.
I also added the following code in MyDebugClass.main to try to debug the issue:
ClassLoader loader = ProblemClass.class.getClassLoader();
Class probCls = loader.loadClass("mypackage.ProblemClass");
//here below is where it errors out
probCls.newInstance();
What could possibly be causing this kind of class loading problem? There is a whole bunch of jars in the classpath so could it be that one of them contains this same class qualifier and the class loader is trying to pick it up from there and not the target directory as specified in the debug build path? How do I find from where the class loader is attempting to load a class, e.g. file system path looking for a .class file or some jar?
Look at the file in the Eclipse "Package Explorer" view. That may give you some help. Also, you say that the .class file is in the target directory, but what about the source .java file?
Other things to check are the Java Build Path of your project properties.
I hope this helps, though you didn't really give enough detail to be able to understand what's really going on.
I'll try to illustrate the problem as simple as I can.
I have a JAR file, which I extracted using Winrar. (The jar file contains an open source android library).
I want to modify this JAR file by adding a new class to the library.
So here are my steps:
First, I created a class using Eclipse and set the package name same as the android's library package name.
Second, I copied this java File to the folder of the other java files in the library.
Third, I tried to compile the JAVA file via the CMD using javac.
The path of the new java file and the other .JAVA and .CLASS files of the library is: C:\com\example\core\
The name of the new java file would be: "MyNewClass.java"
The command I run via the CMD is: javac C:\com\example\core\MyNewClass.java
But, during the compilation I get many errors saying: Cannot find symbols.
I've been looking up for a solution of this problem but couldn't figure how to solve it and make the new JAR File having another class that I created seperately.
What am I missing?
As per earlier comments:
Rather than trying to modify the JAR, you can get access to the full source code of the Universal Image Loader library by cloning the repository using git or hitting "Download ZIP" on the righthand side of the page you linked.
Once you have the source, import the library in your IDE. From there on you'll be able to build the whole thing from scratch, make any adjustments/modifications you like, etc.
Your classpath might be wrong or there might be some mistake in package name.
When a Java program is being compiled the compiler it creates a list of all the identifiers in use. If it can't find what an identifier refers to it cannot complete the compilation. This is what the cannot find symbol error message is saying, it doesn't have enough information to piece together what the Java code wants to execute.
Try:
javac -cp com/* C:\com\example\core\MyNewClass.java
That should make the compiler aware of all the other classes under com/...
I am using one third party jar in my code. In the jar file , in one of the classes, when I opened the class using de-compiler, the code below is written:
java.net.URL fileURL = ClassLoader.getSystemResource("SOAPConfig.xml");
Now I am using this in my webapplication, where should I place this SOAPConfig.xml so that it will find the fileURL.
Note: I have tried putting this XML in WEB-INF/classes folder. But it is not working. Your help will be appreciated.
In Addition: In the explaination you have given, It is telling me not to use this code snippet inside the third party jar in this way...What is the exact usage of this statement
ClassLoader.getSystemResource will load the resource from the system classloader, which uses the classpath of the application as started from the command line. Any classloaders created by the application at runtime (i.e. the one that looks in WEB-INF/classes) are not on the system classpath.
You need to
Look through the script that starts your server, find out which directories are on the classpath there, and put your SOAPConfig.xml in one of those. If necessary, change the classpath in the script to look in a separate directory that's just used for your config file.
Track down the person who used ClassLoader.getSystemResource in the library, kick them squarely in the nuts, and tell them never to do that again.
When I put classpaths into the static class path (ie put them in the classpath.txt file) program works. When I add it dynamically, I get an error that it can't find a properties file in the class path.
Here is what I have
javaaddpath('C:\exchsys\jars\exsystools.jar')
javaaddpath('C:\exchsys\externaljars\log4j.jar')
javaaddpath('C:\exchsys\externaljars\')
javaaddpath('C:\apache-activemq-5.1.0\lib\commons-logging-1.1.jar')
javaaddpath('C:\apache-activemq-5.1.0\activemq-all-5.1.0.jar')
plus my actual code
This leads to the following error:
javax.naming.ConfigurationException: JMSUtilities.loadConfiguration(): Properties file "/exsysjms.properties" not found in the classpath.
The file it is looking for is a in the folder added through this line
javaaddpath('C:\exchsys\externaljars\')
When I put the same paths into the classpath.txt file it works fine. Any ideas?
Your experiencing issues concerning static vs dynamic classpath. A workaround for this issue is shown in this post by using ClassPathHacker.java in order to dynamically load java classes. You may check the other responses as well for further information.