Is there a way to create Java class in VS Code similar to Eclipse New Java Class Wizard?
I would like VS Code to add package and class declarations automatically like Eclipse does.
Couldn't find relevant info in the docs and relevant functionality in plugins.
I faced a similar issue, coming from Eclipse/IDEA background, you can find it difficult to not have a feature in your java IDE to create a new classes, packages etc.
You can use the below VSCode extension : https://github.com/jiangdequan/vscode-java-saber
It is a very handy extension.It provides support/wizard for:
New: Java files(annotation/class/interface/enum/package/JSP/HTML)
Generate Getters and Setters
Copy Qualified Name
Sort Project By Name
Run Maven Goals
Generate Docs
You can try this extension.Search for vscode-java-saber in the extension search and install it.
Related
I'm digging into the source code of the deeplearning for java recently. There is such a class NeuralNetConfiguration in which there are tons of fields that all requires getters and setters. The NeuralNetConfiguration.java source code does not provide any, however.
When I open this project in IntelliJ, ctrl click on the usage of this class, which are methods mostly like, NeuralNetConfiguration.getNInput() or NeuralNetConfiguration.getKernelSize(), the IDE direct me to the compiled class file in which all the getters are defined for each of the field in this class.
Just wonder how this is done since I'm a new bee to java. Posts I found about java reflect suggest that reflect can not add method to a method to a class unless you wrote your own classloader. I check the deep learning for java project and I don't think they have done that.
What bothers me too from time to time is, IntelliJ starts to report errors that those getFields methods could not be resolved since they are not in the source file at all, especially after my building the project using IntelliJ instead of using mvn command line.
The magic happens with the #Data annotation on the class. This annotation is from Project Lombok. There is probably an annotation processor somewhere that hooks into the compiling process and generates these methods.
I have a Java class that i would like to import into my Jython script. Unfortunately, eclipse won't let me create a Java class inside my Jython project.In the window, where you create and name your Java class, I get a message at the top (alongside a red cross) saying, "Source folder is not a Java project" when I type the name of the would be class. How do I rectify this? I need the Java Class to call C code using the JNI (declaring the native method,loading and then calling it). Thank You !!!!!!!
What you can do is to create second module which would be java project. Anyhow, logically it should be that way. Please check out other similar question - PyDev: Jython modules & Java classes in the same project.
Other links that might help - http://pydev.org/manual_101_project_conf2.html
So what nefo_x suggested is correct. You need to create a new Java project that will contain your Java class. Then import the Java package as you would a python module. But there are a few things to watch out for in eclipse to make it work. I list the whole process below:
Your Java class (or classes) should not be in the default package. You need to create a new package and make/put your java class files there.
Export the package as a jar file to some place on your computer.
Add the jar file (located at some place on your computer) to your python path.
Import the package by writing "import PackageName".
The problem for me was that I had my java class in the default package. That does not work due to some naming issues. Anyhow, hope that this helps.
I'm using PyDev 2.5 with Eclipse Indigo and Jython 2.5.3b1 . I have a JAR file that contains certain classes which I'm importing to a PyDev (Jython ) project. They seem to work seamlessly except for Auto completion. The member functions of Java Classes do not auto-complete e.g. pressing the dot '.' operator does not bring up the list for class member functions. The jar file is added to the PyDev-PYTHONPATH external libraries of the PyDev project.
Screenshot of PYTHONPATH external libs
Auto completion does not work for the code below, but it compiles and runs perfectly fine.
from my.testpackage import MyClass
myVar = MyClass("Monkey")
print myVar.getName()
Typing "myVar." does not auto complete
Worth noting that auto completion works if I imported a non custom jar
e.g.
from java.lang import Math
print Math.max(3,5)
Typing "Math." will auto complete
I'm not sure if this functionality even supported in the current version of PyDev. Does anyone actually have this working in their PyDev and Eclipse setup?
Any suggestion would be appreciated.
Thank you,
DM
It may be some issue in your PYTHONPATH configuration. Have you read: http://pydev.org/manual_101_project_conf2.html (most specifically the end of the page: "Project reference for Jython users").
If that doesn't help you, can you explain how are you referencing things? (a screenshot with the config would be nice)
i need an example in Developer defined package in java i cant find any example about it
as you know there are tow kinds of packages in java as the following definistion
Java Packages: The Java language provides the concept of a package as a way to group a number of related classes.
Types
– Standard Java Packages.
– Developer defined package.
brgd
A "developer defined package" is not some special kind of package. What is meant in the text that you quote is that a "developer defined package" is simply a package other than the packages in the standard Java API (packages named java.something, javax.something etc.).
Any package that you create yourself is a "developer defined package". See this tutorial page to learn about using and creating packages:
The Java Tutorials - Creating and Using Packages
Go through the java tutorials.
http://docs.oracle.com/javase/tutorial/java/package/packages.html (and following).
It is strange. 99.999% of code is created in user defined packages. Package is like directory. If you have source directory and want to create package com.mycompany.myprogram just create directories com/mycompany/myprogram under your source directory and then create classes there. I believe that you are using IDE. In this case it helps you to manage your packages. For example in eclipse you can perform right click and then choose New->Package.
At the build(compile) time of my project I need to do code-generation for a java class. The generated java class is a java bean class with a set of getters and setters. At the build time I am getting the name of the class and names of variables. So what I need to do is dynamically generate the java bean from the information which I have.
eg. At the compile time I am getting following data.
class-name=Test
variable-name=aaa
So the generate class should look like following.
public class Test {
public String aaa;
public void setVar(String str) {
this.aaa = str;
}
public String getVar(){
return this.aaa;
}
}
When I searched for a tool that I can use, I found Arch4j [1] interesting but the problem with that is it is not compatible with Apache 2.0 license. I am looking for a project/tool that is compatible with Apache 2.0 license.
I would appreciate if someone can give me some insight on how I can do this.
[1] - http://arch4j.sourceforge.net/components/generator/index.html
Why not just generate the .java file during your build, using a custom ant task or Maven plugin? This seems like a rather easy task which doesn't need any complex library. You could even use a template file with placeholders for the class name and the field name, and generate the real .java file using a replace task.
JET from Eclipse can be used:
http://eclipse.org/articles/Article-JET/jet_tutorial1.html
It can be called by ant: http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jet.doc/references/ant/antTasks.xhtml
And I think from maven: http://mvnrepository.com/artifact/org.eclipse/jet/0.8.0-v20070605
Take a look at javax.tools package. You can create and load a dynamically generated class only with that package.
Just bear in mind you need the JDK available and that's not re-distributable so your customer would need to downloaded it separately ( just like you do in any IDE today )
http://download.oracle.com/javase/6/docs/api/javax/tools/package-summary.html
For instance, you can invoke the java compiler programatically with:
http://download.oracle.com/javase/6/docs/api/javax/tools/JavaCompiler.html
And you can load it with URLClassLoader
Odd suggestion, but it seems like you want to generate beans. Why not use something like apache common's DynaBean? They allow you to create beans at run time. Here is an example of using DynaBean.
Of course this is at run time and not compile time. For compile time, I would recommend using an ant task to compile your source and add a dependency for compile on generation of your classes. You can handle the classes generation by writing a small java application that uses velocity as the java class template's engine.
So your ant task on compile first calls a small java program that generates the java class files using velocity template (delete the old files in ant if needed). Then compile as normal.