我使用Eclipse Mars编译项目。我的理解是Eclipse正在使用它自己的Java编译器(JDT)来编译Java代码。
如何查找Eclipse编译器的版本,以便告诉其他人我使用的是哪个版本?
答案 0 :(得分:2)
ECJ编译器并没有真正独立的版本。
Eclipse Project page上提供的ECJ独立下载编号与Eclipse版本相符(当前Eclipse Neon版本为4.6)。
编译器本身包含在 public class MenuActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private DishesAdapter adapter;
private ArrayList<String> arrayList = new ArrayList<>();
private MyPagerAdapter pagerAdapter;
private ViewPager viewPager;
private TabLayout tabLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
recyclerView = (RecyclerView) findViewById(R.id.recycler_menu);
recyclerView.setHasFixedSize(true);
LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(MenuActivity.this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(horizontalLayoutManagaer);
arrayList = prepareData();
adapter = new DishesAdapter(MenuActivity.this, arrayList);
recyclerView.setAdapter(adapter);
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(MenuActivity.this, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
TextView textView = (TextView) view.findViewById(R.id.tv_name);
textView.setTextColor(Color.parseColor("#FFFFFF"));
adapter.notifyDataSetChanged();
}
}));
setupToolbar();
setupViewPager();
setupToolbar();
}
private ArrayList<String> prepareData() {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("Chineese");
arrayList.add("South Indian");
arrayList.add("Mughalai");
arrayList.add("Local streat");
return arrayList;
}
private void setupViewPager() {
final ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
private void setupToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle("");
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFrag(new TabFragment(), "Soup");
adapter.addFrag(new TabFragment(), "Rice");
adapter.addFrag(new TabFragment(), "Breads");
adapter.addFrag(new TabFragment(), "Curry");
viewPager.setAdapter(adapter);
}
static class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFrag(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
public class MyPagerAdapter extends FragmentPagerAdapter {
private final String[] TITLES = {"Soups", "Rice", "Breads", "Curry"};
final int tabCount;
public MyPagerAdapter(FragmentManager fm, int tabCount) {
super(fm);
this.tabCount = tabCount;
}
@Override
public CharSequence getPageTitle(int position) {
return TITLES[position];
}
@Override
public int getCount() {
return TITLES.length;
}
@Override
public Fragment getItem(int position) {
if (position == 0) {
return InfoFragment.newInstance(position);
} else {
return InfoFragment.newInstance(position);
}
}
}
}
插件中,该插件有自己的版本(目前为3.12.0)
答案 1 :(得分:1)
我推荐你:
1:How to change JDK version for an Eclipse project
2:changing eclipse's java compiler to jdk7
3:how do I get eclipse to use a different compiler version for Java?
答案 2 :(得分:1)
您需要先进入Java EE Perspective。为此,转到功能区然后: 窗口&gt;透视&gt; Open Perspective&gt;其他&gt; Java EE。
NB:如果您没有看到这个,那么这意味着您没有安装Java EE透视图:请参阅如何在此处下载:
How to add Java EE perspective to Eclipse
之后,打开Package Explorer。然后右键单击Java Project并选择Properties。在属性窗口中,应该有一个“Project Facets”选项。此页面列出了编译器中所有Facets的版本。然后,您还可以查看Java编译器的版本号。
如果需要更改此设置,请单击“修改项目”。然后,单击要更改它的构面。通过从Facet的名称(Java编译器)旁边的下拉菜单中选择版本来执行此操作。单击“完成”,然后单击“确定”。
希望这有帮助!
答案 3 :(得分:0)
将command line用于独立的ECJ:
java -jar ecj.jar -version
示例:
从https://mvnrepository.com/artifact/org.eclipse.jdt.core.compiler/ecj/4.6.1获取ECJ:
...> java -jar ecj-4.6.1.jar -version
Eclipse Compiler for Java(TM) v20160829-0950, 3.12.1, Copyright IBM Corp 2000, 2015. All rights reserved.
从http://archive.eclipse.org/eclipse/downloads/drops/R-3.8.2-201301310800/#JDTCORE获取ECJ:
...> java -jar ecj-3.8.2.jar -version
Eclipse Compiler for Java(TM) v20130121-145325, 3.8.3, Copyright IBM Corp 2000, 2012. All rights reserved.
(应该注意ECJ版本和已发布的jar名称之间的区别。)
使用JSR-199 api以编程方式执行此操作:
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.ServiceLoader;
import javax.tools.JavaCompiler;
public class CompilerVersion {
public static void main(String[] args) throws Exception
{
// Standalone ECJ from http://repo1.maven.org/maven2/org/eclipse/jdt/ecj/3.13.50/ :
//jar2classpath("E:\\ecj-3.13.50.jar");
// Load JDT Core & Compiler jars from installed Eclipse Oxygen 4.7.0:
String eclipseDir = "D:\\eclipse\\";
jar2classpath(eclipseDir + "plugins\\org.eclipse.jdt.core_3.13.0.v20170516-1929.jar");
jar2classpath(eclipseDir + "plugins\\org.eclipse.jdt.compiler.tool_1.2.0.v20170502-0408.jar");
//Class.forName("org.eclipse.jdt.internal.compiler.tool.EclipseCompiler");
JavaCompiler compiler = ServiceLoader.load(JavaCompiler.class).iterator().next();
compiler.getTask(null, null, null,
Arrays.asList(new String[] {"-version"}), null, null).call();
}
private static void jar2classpath(String jarFilename) throws Exception {
File file = new File(jarFilename);
Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{file.toURI().toURL()});
}
}
应输出到stderr
:
Eclipse Compiler for Java(TM) v20170516-1929, 3.13.0, Copyright IBM Corp 2000, 2015. All rights reserved.