I want to use Git in console and Intellij as my - java

I want to work with Intellij but without it's git plugin.
I worked with eclipse + git in console and never had a problem. Just push/pull/commit/add etc. and opened the files with eclipse.
Now that i've switched to Intellij, i get many errors, no matter how i open/import the pulled files to Intellij.
Most of the times it look like this:
Exception in thread "main" java.lang.NullPointerException
at Test.main(Test.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Or even this:
Exception in thread "main" java.io.FileNotFoundException: C:\Users\John\Desktop\Test\Program\GitFiles\GG\DC\out\production\DC\level1.txt (The system cannot find the specified path.)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72)
at model.Map.mapImport(Map.java:35)
at model.Map.<init>(Map.java:26)
at model.Model.initialize(Model.java:120)
at model.Model.<init>(Model.java:37)
at Test.main(Test.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
However, is there any way to absolutely correcly import Project Files into Intellij that have been correctly pulled via Git?
I even have the suspicion that the Git-Plugin from Intellij migtht sabotage everything, because it notices there is Git on the folder i am working with.
I've wasted many hours on this problem, i would be tremendously happy about help!
Greetings,
John

If you don't want to use Git inside IntelliJ you should disable it. Go to Configure (In welcome menu) > Plugins > Git Integration , and deselect it. Looks like this
Hope it helped you.

That finally did it. i have played around before with the outputpath settings, but there is one configuration i had missed:
1. Project Settings - Project - Output path (choose EXTERNAL output ( not into Project files itself), wherever else you want)
2.Project Settings - Modules - Paths - Inherit project compile output path.

Related

java.lang.NoClassDefFoundError when trying to instantiate class from jar

I did found quite a lot about this error, but somehow none of the suggested solutions resolved the problem.
I am trying to use JNA bindings for libgphoto2 under Ubuntu in Eclipse (moderate experience with Java on Eclipse, none whatsoever on Ubuntu, I'm afraid). The bindings in question I want to use are here:
http://angryelectron.com/projects/libgphoto2-jna/
I followed the steps described on that page, and made a simple test client that failed with the above error. So I reduced the test client until the only thing I tried to do was to instantiate a GPhoto2 object, which still produced the error. The test client looks like this:
import com.angryelectron.gphoto2.*;
public class test_class
{
public static void main(String[] args)
{
GPhoto2 cam = new GPhoto2();
}
}
The errors I get take up considerably more space:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Structure
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at test_class.main(test_class.java:12)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Structure
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
libgphoto2 itself is installed, it runs from the command line, I even have the development headers and am able to call GPhoto2 functions from python, so the problem can't be located there.
When looking at the .class files in Eclipse, however, they didn't have any definitions. So I figured that might be the problem, especially since there was an error when building the whole thing with ant (although the .jar was succesfully exported, from what I could make out the error concerned only the generation of documentation).
So I loaded the source into eclipse and built the .jar myself. At this occasion Eclipse stated there were warnings during the build (though no errors), but didn't show me the actual warnings. If anyone could tell me where the hell the build log went, that might already help something. I searched for it everywhere without success, and if I click on "details" in eclipse it merely tells me where the warnings occured, not what they were.
Be that as it may, a warning isn't necessarily devastating, so I imported the resulting Jar into the above client. I checked the .class files, this time they contained all the code. But I still get the exact same list of errors (yes, I have made very sure that the old library was removed from the classpath and the new ones added. I repeated the process several times, just in case).
Since I don't have experience with building jars, I made a small helloworld jar, just to see if I could call that from another program or if I'd be getting similar errors. It worked without a hitch. I even tried to reproduce the problem deliberately by exporting it with various options, but it still worked. I tried re-exporting the library I actully need with the settings that had worked during my experiment, but they still wouldn't run. I'm pretty much stuck by now. Any hints that help me resolve the problem would be greatly appreciated.
In addition to what #Paul Whelan has said. You might have better luck by just get the missing jar directly.
Get the missing library here, set the classpath and then re-run the application again and see whether it will run fine or not.
What version of java are you using com/sun/jna/Structure may only work with certain JVMs.
In general, packages such as sun., that are outside of the Java platform, can be different across OS platforms (Solaris, Windows, Linux, Macintosh, etc.) and can change at any time without notice with SDK versions (1.2, 1.2.1, 1.2.3, etc). Programs that contain direct calls to the sun. packages are not 100% Pure Java.
More details here
Your jar needs a MANIFEST.MF which tells your application where the library is found. Create the file in you project root-directory in eclipse and add the following lines:
Manifest-Version: 1.0
Class-Path: <PATH_TO_LIB__CAN_BE_RELATIVE>.jar // e.g Class-Path: ../test.jar
<empty line>
Right-click your project in eclipse, go to Export->next->next->next->Use existing manifest from workspace, select it and click on finish. This should work.
Another solution is to compile the classes into the jar itself with Maven.

What are the JARs required for Hadoop project at startup?

This must seem like an idiotic question but I am new to Hadoop and was trying to run a simple example. However, I keep running into problems with JAR files and dont seem to have the correct imports. I am using cloudera CDH 4 and it has a hole lot of JAR files to choose from with several versions of each. Since I am just starting off am not being able to differentiate. Presently i am getting this exception :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/configuration/Configuration
at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<init>(DefaultMetricsSystem.java:38)
at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<clinit>(DefaultMetricsSystem.java:36)
at org.apache.hadoop.security.UserGroupInformation$UgiMetrics.create(UserGroupInformation.java:120)
at org.apache.hadoop.security.UserGroupInformation.<clinit>(UserGroupInformation.java:236)
at org.apache.hadoop.mapreduce.task.JobContextImpl.<init>(JobContextImpl.java:72)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:144)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:131)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:139)
at com.ayon.hadoop.firstimpl.Driver1.main(Driver1.java:23)Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.Configuration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 9 more
It is probably because of a wrong JAR file import. So my question is this:
Can anyone tell me what are the basic JAR files needed to start up a simple Hadoop job? Also any pointers to the above exception will be much appreciated.
To include all the necessary jar files, compile your code using the following command:
# javac -cp `$HADOOP_HOME\bin\hadoop classpath` YourClassFile.java
Please note the quotes
If you're using Eclipse, follow below steps to add JARs to your project
1.Right click on the project
2.Go to Properties
3.Click on "Java Build Path"
4.Libraries Tab
5.Add External JARs
6.Select the path "/usr/local/hadoop"
7.Select all "JAR files" & add all JARs
8.Again "Add EXternal JARs"
9.Go to path "/usr/local/hadoop/lib"
10.ADD all JARs in there
11.Click "Ok"
You're set. Hope this helps.. again it depends on the Eclipse version you're using.

using eclipse, java maven project compiles but gives error when running

There are a large number of answers to the error I'm getting, but each of the solutions that I've tried (that I understand at least) have not solved my problem.
My project layout in Eclipse looks like this:
MavenProject1
src
resources
etc.
MavenProject2
src
resources
etc.
MavenProjectX
src
resources
etc.
Each project compiles and runs fine. But what I'm trying to do is use one of the projects, say some of the code in MavenProject2, in MavenProject1. I've updated the build path and information so that I can import MavenProject2 into MavenProject1 and reference the methods I want.
The reference to the MavenProject2 method in MavenProject1 enumerates and doesn't give an error in the editor (i.e. com.MavenProject2.Method()), and MavenProject1 compiles. But when I try to run it, I get the error below. I've tried fixing the classpath (as I understand it, which could be wrong), I've tried adding the project, external jar, just about every option, in the run configuration for the project, but I keep hitting the same error on line in MavenProject1 that calls the method in MavenProject2.
[WARNING] java.lang.reflect.InvocationTargetException at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
> java.lang.reflect.Method.invoke(Unknown Source) at
> org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297) at
> java.lang.Thread.run(Unknown Source) Caused by:
> java.lang.NoClassDefFoundError: com/MavenProject2/Method_From2 at
> com.MP1.MP1.main(CAPI.java:154) ... 6 more Caused by:
> java.lang.ClassNotFoundException: com.MavenProject2.Method_From2
When you first build the projects that your current project depends on, make sure they are stored in your local maven repository. Then when you add those as dependencies to your project's pom.xml this should hopefully resolve it for the build.

problems using PMD in IntelliJ IDEA

I was trying to install the PMD plugin to my IntelliJ IDE. I have followed the instructions but when trying to run the pmd check I am getting the following exception. From what it seems the “.” Is being parsed as a / which produce a wrong file name for the class loader.
Meaning the path: Even though the settings are
-cp %CLASSPATH%; C:/Development/IDE/Utils/PMDPlugin/lib/pmd-4.2.5.jar; C:\Development\IDE\Utils\PMDPlugin\lib\asm-3.1.jar; C:\Development\IDE\Utils\PMDPlugin\lib\jaxen-1.1.1.jar net.sourceforge.pmd.PMD "$FilePath$" ideaj unusedcode,imports "$Sourcepath$" $FileClass$.method $FileName$
From some reason it is still looking for C:/Development/IDE/Utils/PMDPlugin/lib/pmd-4/2/5/jar
Here is the exception:
java.lang.NoClassDefFoundError: C:/Development/IDE/Utils/PMDPlugin/lib/pmd-4/2/5/jar;
Caused by: java.lang.ClassNotFoundException: C:.Development.IDE.Utils.PMDPlugin.lib.pmd-4.2.5.jar;
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: C:/Development/IDE/Utils/PMDPlugin/lib/pmd-4.2.5.jar;. Program will exit.
Exception in thread "main"
I am using Intelli IDEA 10.0.3
Build #IC 103.288 built on April 2011
JDK 1.6.0_21
Do you have any advices?? Thanks
Looks like you have spaces between your CLASSPATH entries. That won't do; remove them.
UPDATE:
I downloaded PMD and managed to make it run. I followed the directions that you posted, replacing the path to PMD with my own. I'd recommend not using a path that has spaces in it.
The one thing that was balky was %JAVA_HOME%, so I replaced it with the hard-wired path to my Java /bin. Once I did that, all was well.
I'd ask why you think PMD is better than the inspector tools built into IntelliJ? I'd rather check boxes to set rules than have to do all the nonsense that PMD requires.
Once I was satisfied that I could make it work I deleted it. I'd rather run Inspector.

Why Exception in thread "main" java.lang.NoClassDefFoundError:?

I run my software through Eclipse. Yesterday everything was fine. I made not changes to the code but today, when I am trying to run it again I get the following error messages:
Exception in thread "main" java.lang.NoClassDefFoundError: coloredtrails/CTListener
at test.DemoPlayer1.createAndShowGUI(DemoPlayer1.java:23)
at test.DemoPlayer1.main(DemoPlayer1.java:39)
Caused by: java.lang.ClassNotFoundException: coloredtrails.CTListener
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Why it does not see the class? What could be the reason of that? How can I resolve the problem?
A NoClassDefFoundError (almost) always means that your classpath is wrong. Make sure that your classpath includes the base directory of the coloredtrails package. (Ofcourse, also make sure that the file coloredtrails\CTListener.class actually exists).
When running from the command line:
You can set the classpath by setting the CLASSPATH environment variable, or by specifying it with the -cp or -classpath option on the command line when you run your program. For example:
java -cp C:\MyProject\classes coloredtrails.CTListener
edit - Looking at the stack trace and seeing URLClassLoader in there makes me think that you are trying to run a Java applet. To learn how to correctly deploy applets, so that all classes the applet needs can be found, see this tutorial: Deploying an Applet.
Sometimes, my Eclipse (Indigo on MacOSX) does that, expecially if I do changes (removing files, moving them around) to the project structure on the filsystem directly.
Basically, eclipse cannot find the source folder anymore, so he doesn't compile the source but tries to run it anyway (all this without a warning or a reference to the problem).
To fix it, remove the source folder from the build path (=right click on the src folder under the project in the package explorer, then choose "Build-path->Remove from Build-path". Then, add it again (=right click on the folder under the project in the package explorer and choose "Add to build-path"). This makes the src folder "visible" to the compiler again and fixes the problem.

Categories